c#实现队列(Queue)


 1  public   class  Node
 2      {
 3           private  Node _node;
 4           private   object  _value;
 5 
 6           public  Node( object  v)
 7          {
 8               this ._value  =  v;
 9               this ._node  =   null ;
10          }
11 
12           public  Node NodeNext
13          {
14               get  {  return  _node; }
15               set  { _node  =  value; }
16          }
17           public   object  Value
18          {
19               get  {  return  _value; }
20          }
21 
22      }

 1  public   class  Queue
 2      {
 3           public  Queue() { }
 4           private   int  count = 0 ; // 队列中节点的个数
 5           private  Node nOutNode = null ; // 输出端
 6           private  Node oInNode = null ; // 输入端 
 7   
 8           /// <summary>  
 9           ///  队列中节点总数 
10           ///   </summary>  
11           public   int  Count 
12          { 
13               get return  count;} 
14          } 
15           
16           ///   <summary>  
17           ///  入队列 
18           ///   </summary>  
19           ///   <param name="o"> 进队对象 </param>  
20           public   void  Push( object  o) 
21          { 
22              Node nextNode  =   new  Node(o);
23               if  (oInNode  !=   null )
24              {
25                  oInNode.NodeNext  =  nextNode;
26              }
27 
28              oInNode  =  nextNode;
29 
30               if  (nOutNode  ==   null )
31              {
32                  nOutNode  =  oInNode;
33              }
34              count ++
35          } 
36           ///   <summary>  
37           ///  出队 
38           ///   </summary>  
39           ///   <returns> 队列当前节点的值 </returns>  
40           public   object  Pop() 
41          { 
42               if (nOutNode == null
43              { 
44                   throw   new  Exception( " 队列空! " ); 
45              } 
46               else  
47              { 
48                   object  objValue  =  nOutNode.Value; 
49                  nOutNode  =  nOutNode.NodeNext; 
50                  count --
51                   return  objValue; 
52              } 
53          }
54 
55 
56      }

源代码: /Files/HeroBeast/Queue.rar

转载于:https://www.cnblogs.com/HeroBeast/archive/2008/07/14/1242976.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值