• 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             getreturn 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

  • 相关阅读:
    [图解数据结构] 线性表
    利用爬虫获取网上医院药品价格信息 (上)
    手把手教你写网络爬虫(1):网易云音乐歌单
    用python实现与小米网关通讯
    eclipse添加lombok无法启动
    mongodb数据出现undefined如何查询
    初探active mq
    base64和图片互转
    设置Linux下Mysql表名不区分大小写
    Windows下安装MySQL5.6绿色版
  • 原文地址:https://www.cnblogs.com/HeroBeast/p/1242976.html
Copyright © 2020-2023  润新知