C#堆栈
using System;
namespace ZH.DataFrame.AbstractData
{
ObjectStackADT object堆栈#region ObjectStackADT object堆栈
/**//// <summary>
/// object堆栈(先进后出)
/// </summary>
public class StackADT
{
private object[] s;
private int N;
public StackADT(int maxN)
{
s=new object[maxN];N=0;
}
public bool isEmpty()
{
return (N==0);
}
/**//// <summary>
/// 推入
/// </summary>
/// <param name="item"></param>
public void push(object item)
{
s[N++]=item;
}
/**//// <summary>
/// 推出
/// </summary>
/// <returns></returns>
public object pop()
{
object t=s[--N];
s[N]=null;
return t;
}
}
#endregion
NodeStack(int) 链表int堆栈#region NodeStack(int) 链表int堆栈
/**//// <summary>
/// 链表int堆栈
/// </summary>
public class NodeStack
{
private class Node
{
public int item;public Node next;
public Node(int item1,Node next)
{
item=item1;this.next=next;
}
}
private Node head;
public NodeStack()
{
head=null;
}
public bool isEmpty()
{
return (head==null);
}
public void push(int item)
{
head=new Node(item,head);
}
public int pop()
相关新闻>>
- 发表评论
-
- 最新评论 更多>>