template
class LinkStack
{

public:
  template
  class LinkStackNode
  {
  public:
    T data;
    LinkStackNode * link;
    LinkStackNode(T& value):link(NULL),data(value){}
  };

  LinkStack():top(NULL){}
  void Push(T& value);
  T& GetTop();
  T& Pop();
  bool IsEmpty();
  void MakeEmpty();

private:
    LinkStackNode * top;
};

template
void LinkStack::Push(T &value)
{
  LinkStackNode * add=new LinkStackNode(value);
  add->link=top;
  top=add;
}

template
T& LinkStack::GetTop()
{
  if(top==NuLL)
  {
    cout<<"栈为空!"<    exit(0);
  }
  else
  {
    return top->data;
  }
}

template
T& LinkStack::Pop()
{
  if(top==NULL)
  {
    cout<<"栈为空!"<    exit(0);
  }
  else
  {
    LinkStackNode * old=top;
    top=top->link;
    T data=old->data;
    delete old;
    return data;
  }
}

template
bool LinkStack::IsEmpty()
{
  return top==NULL;
}

template
void LinkStack::MakeEmpty()
{
  while(!this->IsEmpty())
  {
    this->Pop();
  }
}