第二个。。
所在版块:心情闲聊 发贴时间:2004-05-04 03:06  评分:

用户信息
复制本帖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.

 相关帖子 我要回复↙ ↗回到正文
发一贴。庆祝下偶写的第一个C#程序。 辰星   (143 bytes , 498reads )
昨天晚上在canteen看见楼主了 只是看看   (0 bytes , 245reads )
第二个。。 辰星   (1070 bytes , 351reads )
^o^ 辰星   (52 bytes , 245reads )