|
|
|
|
复制本帖HTML代码
|
高亮:
今天贴
X 昨天贴
X 前天贴
X |
using System;
class Stack
{
private Node first=null;
public bool Empty()
{
return (first==null);
}
public object Pop()
{
if(first==null)
throw new Exception("Cann'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);
}
public void Push(object o1,object o2)
{
Push(o1);
Push(o2);
}
}
class Node
{
public Node Next;
public object Value;
public Node(object value)
{
Value=value;
Next=null;
}
public Node(object value, Node next)
{
Next=next;
Value=value;
}
}
class Test
{
public static void Main()
{
Stack s=new Stack();
for(int i=0;i<10;i++)
{
s.Push(i);
}
s.Push(-10,-20);
while(!s.Empty()
{
Console.WriteLine(s.Pop());
}
}
}
.
|
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法! |
Many events have slipped by. And you are here, now, always.
People are not memories that you can put into words. They live.
|
|