using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{public class Stack
{
Entry top;
public void Push(object data)
{
top = new Entry(top, data); //进栈
}
public object Pop() //出栈
{
if (top == null) throw new InvalidOperationException();
object result = top.data;//获取堆栈顶端数据
top = top.next;
return result;
}
class Entry
{
public Entry next;
public object data;
public Entry(Entry next, object data)
{
this.next = next;
this.data = data;
}
}
class Stacktest
{
static void Main()
{
Stack S = new Stack();
S.Push(1); ///1进栈
S.Push(10); ///10进栈
S.Push(100); ///100进栈
Console.WriteLine(S.Pop()); ///出栈,输出100
Console.WriteLine(S.Pop());///出栈,输出10
Console.WriteLine(S.Pop());///出栈,输出1
Console.ReadKey();
}
}
}
}