(2)Stack类
栈,后进先出。push方法入栈,pop方法出栈。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stack sk = new Stack();
Stack sk2 = new Stack();
foreach (int i in new int[4] ...{ 1, 2, 3, 4 })
{
sk.Push(i);//填充
sk2.Push(i);
}
foreach (int i in sk)
{
Console.WriteLine(i);//遍历
}
sk.Pop();
Console.WriteLine("Pop");
foreach (int i in sk)
{
Console.WriteLine(i);
}
sk2.Peek();//弹出最后一项不删除//清清月儿 http://blog.csdn.net/21aspnet/
Console.WriteLine("Peek");
foreach (int i in sk2)
{
Console.WriteLine(i);
}
while (sk2.Count != 0)
{
int i = (int)sk2.Pop();//清空
sk2.Pop();//清空
}
Console.WriteLine("清空");
foreach (int i in sk2)
{
Console.WriteLine(i);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stack sk = new Stack();
Stack sk2 = new Stack();
foreach (int i in new int[4] ...{ 1, 2, 3, 4 })
{
sk.Push(i);//填充
sk2.Push(i);
}
foreach (int i in sk)
{
Console.WriteLine(i);//遍历
}
sk.Pop();
Console.WriteLine("Pop");
foreach (int i in sk)
{
Console.WriteLine(i);
}
sk2.Peek();//弹出最后一项不删除//清清月儿 http://blog.csdn.net/21aspnet/
Console.WriteLine("Peek");
foreach (int i in sk2)
{
Console.WriteLine(i);
}
while (sk2.Count != 0)
{
int i = (int)sk2.Pop();//清空
sk2.Pop();//清空
}
Console.WriteLine("清空");
foreach (int i in sk2)
{
Console.WriteLine(i);
}
}
}
}