中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

Genericとは?第7回 StackとQueue

第7回 Stack<T>とQueue<T>

古来よりメモリ管理等のやり方として、スタック方式(LIFO(FILO)方式)と、キュー方式(FIFO方式)というが存在する。

これらの方式などはまさにGenericsの格好の的である。

1.x C#
Stack st = new Stack();
st.Push("1");
st.Push("2");
st.Push("3");
Debug.WriteLine((string)st.Pop());
Debug.WriteLine((string)st.Pop());
Debug.WriteLine((string)st.Pop());
Queue qu = new Queue();
qu.Enqueue("1");
qu.Enqueue("2");
qu.Enqueue("3");
Debug.WriteLine((string)qu.Dequeue());
Debug.WriteLine((string)qu.Dequeue());
Debug.WriteLine((string)qu.Dequeue());
1.x VB
Dim st As Stack = New Stack
st.Push("1")
st.Push("2")
st.Push("3")
Debug.WriteLine(CStr(st.Pop()))
Debug.WriteLine(CStr(st.Pop()))
Debug.WriteLine(CStr(st.Pop()))
Dim qu As Queue = New Queue
qu.Enqueue("1")
qu.Enqueue("2")
qu.Enqueue("3")
Debug.WriteLine(CStr(qu.Dequeue()))
Debug.WriteLine(CStr(qu.Dequeue()))
Debug.WriteLine(CStr(qu.Dequeue()))
1.x MC++
Stack __gc *st = new Stack();
st->Push(S"1");
st->Push(S"2");
st->Push(S"3");
Debug::WriteLine(static_cast<String*>(st->Pop()));
Debug::WriteLine(static_cast<String*>(st->Pop()));
Debug::WriteLine(static_cast<String*>(st->Pop()));
Queue __gc *qu = new Queue();
qu->Enqueue(S"1");
qu->Enqueue(S"2");
qu->Enqueue(S"3");
Debug::WriteLine(static_cast<String*>(qu->Dequeue()));
Debug::WriteLine(static_cast<String*>(qu->Dequeue()));
Debug::WriteLine(static_cast<String*>(qu->Dequeue()));

いづれも1.x系でも便利に使ってきたと思う。

これらが2.0では下記のようになる

2.0 C#
Stack<string> ss = new Stack<string>();
ss.Push("1");
ss.Push("2");
ss.Push("3");
Debug.Print(ss.Pop());
Debug.Print(ss.Pop());
Debug.Print(ss.Pop());
Queue<string> qs = new Queue<string>();
qs.Enqueue("1");
qs.Enqueue("2");
qs.Enqueue("3");
Debug.Print(qs.Dequeue());
Debug.Print(qs.Dequeue());
Debug.Print(qs.Dequeue());
2.0 VB
Dim ss As Stack(Of String) = New Stack(Of String)()
ss.Push("1")
ss.Push("2")
ss.Push("3")
Debug.Print(ss.Pop())
Debug.Print(ss.Pop())
Debug.Print(ss.Pop())
Dim qs As Queue(Of String) = New Queue(Of String)()
qs.Enqueue("1")
qs.Enqueue("2")
qs.Enqueue("3")
Debug.Print(qs.Dequeue())
Debug.Print(qs.Dequeue())
Debug.Print(qs.Dequeue())
2.0 C++/CLI
Stack<String^>^ ss = gcnew Stack<String^>();
ss->Push("1");
ss->Push("2");
ss->Push("3");
Debug::Print(ss->Pop());
Debug::Print(ss->Pop());
Debug::Print(ss->Pop());
Queue<String^>^ qs = gcnew Queue<String^>();
qs->Enqueue("1");
qs->Enqueue("2");
qs->Enqueue("3");
Debug::Print(qs->Dequeue());
Debug::Print(qs->Dequeue());
Debug::Print(qs->Dequeue());

投稿日時 : 2004年12月14日 23:24

コメントを追加

# http://askjeeves.oimlya.com
http://foto-porn.oimlya.com
http://tamilsex.oimlya.com
http://hunyellow.navseh.com
http://bellsouthnet.mnoga.com
,http://askjeeves.oimlya.com
http://foto-porn.oimlya.com
http://tamilsex.oimlya.com 2006/10/19 19:10 http://askjeeves.oimlya.com
http://foto-porn.o

http://askjeeves.oimlya.com
http://foto-porn.oimlya.com
http://tamilsex.oimlya.com
http://hunyellow.navseh.com
http://bellsouthnet.mnoga.com
,http://askjeeves.oimlya.com
http://foto-porn.oimlya.com
http://tamilsex.oimlya.com
http://hunyellow.navseh.com
http://bellsouthnet.mnoga.com
,http://askjeeves.oimlya.com
http://foto-porn.oimlya.com
http://tamilsex.oimlya.com
http://hunyellow.navseh.com
http://bellsouthnet.mnoga.com

# re: Genericとは?第7回 Stack<T 2007/01/10 3:26 t5btx5gdme

9r00osmstvr http://www.737288.com/933698.html 54f3lo6o

# re: Genericとは?第7回 Stack<T 2007/01/24 5:35 llilwv4zb7

fp37qhpqjqujc http://www.132958.com/459758.html pm5h9yxkavezu8lp4

# re: Genericとは?第7回 Stack<T 2007/01/24 5:35 llilwv4zb7

fp37qhpqjqujc wdh2v7n3wzczyqnh pm5h9yxkavezu8lp4

タイトル
名前
URL
コメント