C#通過鏈表實現(xiàn)隊列的方法
更新時間:2015年04月27日 11:23:38 作者:lele
這篇文章主要介紹了C#通過鏈表實現(xiàn)隊列的方法,涉及C#操作鏈表的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了C#通過鏈表實現(xiàn)隊列的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
public class Node
{
public int Data { get; set; }
public Node Next { get; set; }
public Node(int data)
{
this.Data = data;
}
}
public class Queue
{
private Node _head;
private Node _tail;
private int _count = 0;
public Queue() { }
public void Enqueue(int data)
{
Node _newNode = new Node(data);
if (_head == null)
{
_head = _newNode;
_tail = _head;
}
else
{
_tail.Next = _newNode;
_tail = _tail.Next;
}
_count++;
}
public int Dequeue()
{
if (_head == null)
{
throw new Exception("Queue is Empty");
}
int _result = _head.Data;
_head = _head.Next;
return _result;
}
public int Count
{
get
{
return this._count;
}
}
}
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
在C#的類或結(jié)構(gòu)中重寫ToString方法的用法簡介
這篇文章主要介紹了在C#的類或結(jié)構(gòu)中重寫ToString方法的用法簡介,需要的朋友可以參考下2016-01-01
C#中使用JSON.NET實現(xiàn)JSON、XML相互轉(zhuǎn)換
這篇文章主要介紹了C#中使用JSON.NET實現(xiàn)JSON、XML相互轉(zhuǎn)換的相關(guān)代碼及示例,需要的朋友可以參考下2015-11-11
C#中DataTable和List互轉(zhuǎn)的示例代碼
很多場景下,我們需要將List轉(zhuǎn)換成為DataTable,本文主要介紹了C#中DataTable和List互轉(zhuǎn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04

