C# よく使いそうなコード2
スタック
以下の名前空間を定義
using System.Collections.Generic;
例
Stack<string> test = new Stack<string> (); test.Push("one"); test.Push("two"); Console.WriteLine(test.Pop()); Console.WriteLine(test.Pop());
使えそうなメソッド
・Pop
先頭にあるオブジェクトを削除し返す
・Push
先頭にオブジェクトを挿入
・Clear
すべてのオブジェクトを削除
・Peek
先頭にあるオブジェクトを削除せずに返す
・Contains
ある要素がスタック内に存在するか判断する
キュー
以下の名前空間を定義
using System.Collections.Generic;
例
Queue<string> test = new Queue<string> (); test.Enqueue("one"); test.Enqueue("two"); Console.WriteLine(test.Dequeue()); Console.WriteLine(test.Dequeue());
使えそうなメソッド
・Enqueue
キューの末尾にオブジェクトを追加
・Dequeue
先頭のオブジェクトを削除し、返す
・Peek
先頭のオブジェクトを削除せずに返す
・Clear
すべてのオブジェクトを削除
参考文献
System.Collections.Generic 名前空間 (Microsoft Developer Network)
http://msdn.microsoft.com/ja-jp/library/system.collections.generic(v=vs.110).aspx