進哥的布拉格

Chin Gooole's Blog

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

轉自 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;
        }
    }
}

 

 

 

posted on 2008-10-24 15:05  進哥  阅读(271)  评论(0编辑  收藏  举报