C#集合本質(zhì)之隊(duì)列的用法詳解
隊(duì)列和堆棧都是約束版的鏈表,就像在超市購(gòu)物,隊(duì)列是先進(jìn)先出的數(shù)據(jù)結(jié)構(gòu)。
接著上一篇,派生于鏈表類(lèi)List,來(lái)模擬一個(gè)隊(duì)列。
namespace LinkedListLibrary
{
public class QueueInheritance : List
{
public QueueInheritance() : base("queue"){}
//入隊(duì):到最后面
public void Enqueue(object dataValue)
{
InsertAtBack(dataValue);
}
//出隊(duì):在最前面刪除
public object Dequeue()
{
return RemoveFromFront();
}
}
}客戶(hù)端調(diào)用。
public static void Main(string[] args)
{
QueueInheritance queue = new QueueInheritance();
bool aBoolean = true;
char aChar = 'a';
int anInt = 1;
string aStr = "hello";
queue.Enqueue(aBoolean);
queue.Display();
queue.Enqueue(aChar);
queue.Display();
queue.Enqueue(anInt);
queue.Display();
queue.Enqueue(aStr);
queue.Display();
object removedObject = null;
try
{
while (true)
{
removedObject = queue.Dequeue();
Console.WriteLine(removedObject + "出隊(duì)列~~");
queue.Display();
}
}
catch (EmptyListException emptyListException)
{
Console.Error.WriteLine(emptyListException.StackTrace);
}
Console.ReadKey();
}
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- C#實(shí)現(xiàn)萬(wàn)物皆可排序的隊(duì)列方法詳解
- C#中的隊(duì)列Queue<T>與堆棧Stack<T>
- C#實(shí)現(xiàn)優(yōu)先隊(duì)列和堆排序
- C#數(shù)據(jù)類(lèi)型實(shí)現(xiàn)背包、隊(duì)列和棧
- C#集合之隊(duì)列的用法
- C#隊(duì)列的簡(jiǎn)單使用
- C#實(shí)現(xiàn)泛型動(dòng)態(tài)循環(huán)數(shù)組隊(duì)列的方法
- C#多線程處理多個(gè)隊(duì)列數(shù)據(jù)的方法
- C#實(shí)現(xiàn)順序隊(duì)列和鏈隊(duì)列的代碼實(shí)例
相關(guān)文章
C#實(shí)現(xiàn)將json轉(zhuǎn)換為DataTable的方法
這篇文章主要介紹了C#實(shí)現(xiàn)將json轉(zhuǎn)換為DataTable的方法,涉及C#操作json及DataTable的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
C# 中使用Stopwatch計(jì)時(shí)器實(shí)現(xiàn)暫停計(jì)時(shí)繼續(xù)計(jì)時(shí)功能
這篇文章主要介紹了C# 中使用Stopwatch計(jì)時(shí)器可暫停計(jì)時(shí)繼續(xù)計(jì)時(shí),主要介紹stopwatch的實(shí)例代碼詳解,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03

