全部博文(1293)
分类: C#/.net
2014-06-23 16:24:38
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace CSharpStackTest
{
class Program
{
private static Stack mStack;
private static Queue mQueue;
private static int tmpValue = 0;
static void Main(string[] args)
{
mStack = new Stack();
Console.WriteLine("Begin to push stack:");
for (int i = 0; i < 4; i++)
{
mStack.Push(i);
Console.Write("{0},", i);
}
Console.WriteLine();
Console.WriteLine("Begin to pop stack:");
for (int i = 0; i < 4; i++)
{
tmpValue = (int)mStack.Pop();
Console.Write("{0},", tmpValue);
}
Console.WriteLine("\n**************************************");
Console.WriteLine();
mQueue = new Queue();
Console.WriteLine("Begin to Enqueue:");
for (int j = 0; j < 4; j++)
{
mQueue.Enqueue(j);
Console.Write("{0},", j);
}
Console.WriteLine();
Console.WriteLine("Begin to Enqueue:");
for (int j = 0; j < 4; j++)
{
tmpValue = (int)mQueue.Dequeue();
Console.Write("{0},", tmpValue);
}
Console.WriteLine("\n**************************************");
Console.WriteLine();
Console.ReadLine();
}
}
}
上述结果弱弱的的验证了观点:
Stack,后进先出
Queue,先进先出