1 public class Nodes //结点类
2 {
3 public Nodes Next;
4 public object Value;
5 public Nodes(object value) : this(value, null) { }
6 public Nodes(object value, Nodes next)
7 {
8 Next = next;
9 Value = value;
10 }
11 }
2 {
3 public Nodes Next;
4 public object Value;
5 public Nodes(object value) : this(value, null) { }
6 public Nodes(object value, Nodes next)
7 {
8 Next = next;
9 Value = value;
10 }
11 }
1 public class Stack
2 {
3 private int count = 0;
4 private Nodes first = null;//定义首结点
5
6 public bool Empty
7 {
8 get{ return (first == null);}
9 }
10
11
12 public int Count
13 {
14 get{return count;}
15 }
16
17 public object Pop()//入栈
18 {
19 if (first == null)
20 {
21 throw new InvalidOperationException("Can not pop from an empty stack;");
22 }
23 else
24 {
25 object temp = first.Value;
26 first = first.Next;
27 count--;
28 return temp;
29 }
30 }
31
32 public void push(object o)//出栈
33 {
34 first = new Nodes(o, first);
35 count++;
36 }
37
38 public Stack(){ }
39
40
41
42 }
2 {
3 private int count = 0;
4 private Nodes first = null;//定义首结点
5
6 public bool Empty
7 {
8 get{ return (first == null);}
9 }
10
11
12 public int Count
13 {
14 get{return count;}
15 }
16
17 public object Pop()//入栈
18 {
19 if (first == null)
20 {
21 throw new InvalidOperationException("Can not pop from an empty stack;");
22 }
23 else
24 {
25 object temp = first.Value;
26 first = first.Next;
27 count--;
28 return temp;
29 }
30 }
31
32 public void push(object o)//出栈
33 {
34 first = new Nodes(o, first);
35 count++;
36 }
37
38 public Stack(){ }
39
40
41
42 }
源代码:/Files/HeroBeast/Stack.rar