自己动手写一个 堆栈

 

 1 ExpandedBlockStart.gif ContractedBlock.gif   /**/ /// <summary>
 2InBlock.gif        /// 一个简单的 堆栈 
 3ExpandedBlockEnd.gif        /// </summary>

 4 None.gif          public   class  myStack
 5 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 6InBlock.gif            private myNode topNode = null;
 7InBlock.gif            private int count = 0;
 8InBlock.gif
 9ExpandedSubBlockStart.gifContractedSubBlock.gif            /**//// <summary>
10InBlock.gif            /// 出栈
11InBlock.gif            /// </summary>
12ExpandedSubBlockEnd.gif            /// <returns></returns>

13InBlock.gif            public object Pop()
14ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
15InBlock.gif                object objPop = null;
16InBlock.gif                if (topNode == nullreturn null;
17InBlock.gif                
18InBlock.gif                objPop = topNode.Data;
19InBlock.gif                topNode = topNode.Next;
20InBlock.gif
21InBlock.gif                count--;
22InBlock.gif                return objPop;
23ExpandedSubBlockEnd.gif            }

24InBlock.gif
25ExpandedSubBlockStart.gifContractedSubBlock.gif            /**//// <summary>
26InBlock.gif            /// 栈的元素个数
27ExpandedSubBlockEnd.gif            /// </summary>

28ExpandedSubBlockStart.gifContractedSubBlock.gif            public int Countdot.gif{   getdot.gif{return count;}  }
29InBlock.gif
30ExpandedSubBlockStart.gifContractedSubBlock.gif            /**//// <summary>
31InBlock.gif            /// 进栈
32InBlock.gif            /// </summary>
33ExpandedSubBlockEnd.gif            /// <param name="obj"></param>

34InBlock.gif            public void Push(object obj)
35ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
36InBlock.gif                myNode newNode = new myNode();
37InBlock.gif                newNode.Data = obj;
38InBlock.gif                newNode.Next = topNode;
39InBlock.gif
40InBlock.gif                count++;
41InBlock.gif                topNode = newNode;
42ExpandedSubBlockEnd.gif            }

43InBlock.gif
44InBlock.gif            class myNode
45ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
46InBlock.gif                private object data;
47InBlock.gif                private myNode next;
48InBlock.gif
49InBlock.gif                public myNode Next
50ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
51ExpandedSubBlockStart.gifContractedSubBlock.gif                    get dot.gifreturn next; }
52ExpandedSubBlockStart.gifContractedSubBlock.gif                    set dot.gif{ next = value; }
53ExpandedSubBlockEnd.gif                }

54InBlock.gif
55InBlock.gif                public object Data
56ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
57ExpandedSubBlockStart.gifContractedSubBlock.gif                    get dot.gifreturn data; }
58ExpandedSubBlockStart.gifContractedSubBlock.gif                    set dot.gif{ data = value; }
59ExpandedSubBlockEnd.gif                }

60ExpandedSubBlockEnd.gif            }

61ExpandedBlockEnd.gif        }
posted on 2007-04-16 18:08 K3 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/sskset/archive/2007/04/16/715675.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值