1. 程式人生 > >C#基礎:棧stack和佇列queue

C#基礎:棧stack和佇列queue

棧stack和佇列queue

  這裡只談一下棧和佇列的簡單運用和理解。

//棧Stack  壓棧push  出棧pop 獲取棧頂peek 判斷有沒有contains
			Stack<int> shuzi = new Stack<int>();
			shuzi.Push (10);
			shuzi.Push (20);
			shuzi.Push (30);
			shuzi.Push (40);
			shuzi.Push (50);
			shuzi.Push (60);
			Console.WriteLine (shuzi.Pop());//60
			Console.
WriteLine (shuzi.Pop());//50 Console.WriteLine (shuzi.Peek());//40 Console.WriteLine (shuzi.Contains(50));//False //佇列Queue 入隊Enqueue 出隊Dequeue 判斷有沒有contains Queue<string> str = new Queue<string>(); str.Enqueue ("A"); str.Enqueue ("B"); str.Enqueue ("C"); str.Enqueue ("D");
str.Enqueue ("E"); str.Enqueue ("F"); Console.WriteLine (str.Dequeue());//A Console.WriteLine (str.Dequeue());//B Console.WriteLine (str.Contains("A"));//False

  棧是先進後出,佇列是先進先出。
  2018.10.24,來到CSDN部落格寫的第二篇筆記,本人目前還是初學者,只分享一些簡單的基礎知識,也是為了做一下學習筆記,望讀者加以指正,謝謝!