轉自 http://msdn.microsoft.com/en-us/library/aa664640(VS.71).aspx
using System;
public class Stack
{
private Node first = null;
public bool Empty
{
get
{
return (first == null);
}
}
public object Pop()
{
if (first == null)
throw new Exception("Can't Pop from an empty Stack.");
else
{
object temp = first.Value;
first = first.Next;
return temp;
}
}
public void Push(object o)
{
first = new Node(o, first);
}
private class Node
{
public Node Next;
public object Value;
public Node(object value) : this(value, null) { }
public Node(object value, Node next)
{
Next = next;
Value = value;
}
}
}
public class Stack
{
private Node first = null;
public bool Empty
{
get
{
return (first == null);
}
}
public object Pop()
{
if (first == null)
throw new Exception("Can't Pop from an empty Stack.");
else
{
object temp = first.Value;
first = first.Next;
return temp;
}
}
public void Push(object o)
{
first = new Node(o, first);
}
private class Node
{
public Node Next;
public object Value;
public Node(object value) : this(value, null) { }
public Node(object value, Node next)
{
Next = next;
Value = value;
}
}
}