1
/// <summary>
2
/// 一个简单的 堆栈
3
/// </summary>
4
public class myStack
5
{
6
private myNode topNode = null;
7
private int count = 0;
8
9
/// <summary>
10
/// 出栈
11
/// </summary>
12
/// <returns></returns>
13
public object Pop()
14
{
15
object objPop = null;
16
if (topNode == null) return null;
17
18
objPop = topNode.Data;
19
topNode = topNode.Next;
20
21
count--;
22
return objPop;
23
}
24
25
/// <summary>
26
/// 栈的元素个数
27
/// </summary>
28
public int Count{ get{return count;} }
29
30
/// <summary>
31
/// 进栈
32
/// </summary>
33
/// <param name="obj"></param>
34
public void Push(object obj)
35
{
36
myNode newNode = new myNode();
37
newNode.Data = obj;
38
newNode.Next = topNode;
39
40
count++;
41
topNode = newNode;
42
}
43
44
class myNode
45
{
46
private object data;
47
private myNode next;
48
49
public myNode Next
50
{
51
get { return next; }
52
set { next = value; }
53
}
54
55
public object Data
56
{
57
get { return data; }
58
set { data = value; }
59
}
60
}
61
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61
