以前写的 C# 队列

以前写的 C#  队列 

结点

/// <summary>
    
/// 队列节点
    
/// </summary>
    
/// <typeparam name="T">队列节点保存的对象</typeparam>

     internal   class  TCQueueNode < T >
    
{
        
//init
        public TCQueueNode()
        
{ }


        
private T nodeValue = default(T);                //节点对象

        
private TCQueueNode<T> nextNode = null;                //   节点对应的下一节点地址


        
/// <summary>
        
///  节点对应的下一节点地址
        
/// </summary>

        internal TCQueueNode<T> NextNode
        
{
            
get return nextNode; }
            
set { nextNode = value; }
        }


        
/// <summary>
        
/// 节点的值
        
/// </summary>

        internal T NodeValue
        
{
            
get return nodeValue; }
            
set { nodeValue = value; }
        }



    }

 队列

 

   /// <summary>
    
/// 队列类
    
/// </summary>
    
/// <typeparam name="T">队列结点保存的对象</typeparam>

     public   class  TCQueue < T >
    
{
        
/// <summary>
        
/// 队列类 构造函数
        
/// </summary>

        public TCQueue()
        
{ }

        
        
private int queueLength = 0;            //队列长度
        private TCQueueNode<T> FirstNode = null//队列头
        private TCQueueNode<T> LastNode = null//队列尾 

                      
        
/// <summary>
        
/// 队列长度
        
/// </summary>

        public int QueueLength
        
{
            
get return queueLength; }
        }


       
        
/// <summary>
        
/// 入队
        
/// </summary>
        
/// <param name="NodeValue">对象</param>

        public void Enqueue(T NodeValue)
        
{
            TCQueueNode
<T> QueueNode = new TCQueueNode<T>();  //初始化一个队列结点
            QueueNode.NodeValue = NodeValue;                                //赋值
            if(FirstNode==null)    FirstNode = QueueNode;                   //队列头为null时,设置队列头
            if (LastNode != null)  LastNode.NextNode = QueueNode;           //入队
            LastNode = QueueNode;                                           //队尾后排
            this.queueLength++;                                             //队列长度+1
        }


        
/// <summary>
        
/// 出队
        
/// </summary>
        
/// <returns>对象</returns>

        public T Dequeue()
        
{
            
if (FirstNode == nullreturn default (T);
            TCQueueNode 
<T> tmpNode = FirstNode;
            T reStr 
= tmpNode.NodeValue;
            FirstNode 
= FirstNode.NextNode;
            
this.queueLength--;
            tmpNode 
= null;
            
return reStr;
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值