Stack
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Stack
{
class Program
{
static void Main(string[] args)
{
Stack<int> sk = new Stack<int>();
Stack<int> sk2 = new Stack<int>();
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();//弹出最后一项不删除
Console.WriteLine("Peek");
foreach (int i in sk2)
{
Console.WriteLine(i);
Console.ReadLine();
}
}
}
}
运行结果为:
4
3
2
1
Pop
3
2
1
Peek
4
3
2
1
(此文为转载)