C#通过链表实现队列的方法
本文实例讲述了C#通过链表实现队列的方法。分享给大家供大家参考。具体实现方法如下:
publicclassNode { publicintData{get;set;} publicNodeNext{get;set;} publicNode(intdata) { this.Data=data; } } publicclassQueue { privateNode_head; privateNode_tail; privateint_count=0; publicQueue(){} publicvoidEnqueue(intdata) { Node_newNode=newNode(data); if(_head==null) { _head=_newNode; _tail=_head; } else { _tail.Next=_newNode; _tail=_tail.Next; } _count++; } publicintDequeue() { if(_head==null) { thrownewException("QueueisEmpty"); } int_result=_head.Data; _head=_head.Next; return_result; } publicintCount { get { returnthis._count; } } }
希望本文所述对大家的C#程序设计有所帮助。