unexcepted end of file found
.cpp(126) : fatal error C1004: unexpected end of file found执行 cl.exe 时出错.
那个高手帮我解决一下 谢谢啦
#ifndef LinkNode_H
#define LinkNode_H
#ifndef LinkedStack
#define LinkedStack
#include <iostream.h>
using namespace std;
template<class Type>
struct LinkNode
{
Type data;
LinkNode<Type> *link;
LinkNode(LinkNode<Type> *ptr=NULL) {link=ptr;}
LinkNode(const Type& item, LinkNode<Type> *ptr=NULL)
{data=item;link=ptr;}
};
template<class Type>
class Stack
{
public:
Stack(){};
virtual void Push(const Type &item)=0;
virtual bool Pop(Type &item)=0;
virtual bool GetTop(Type &item) const=0;
virtual bool IsEmpty() const=0;
virtual int getSize() =0;
};
template<class Type>
class LinkedStack:public Stack<Type>
{
public:
LinkedStack():top(NULL){}
~LinkedStack(){MakeEmpty();}
void Push(const Type &item);
bool Pop(Type &item);
bool GetTop(Type &item) const;
bool IsEmpty() const{return (top==NULL) ? true:false;}
int getSize() ;
void MakeEmpty();
// friend ostream& operator<<(ostream& os,SeqStack<Type> &s);
private:
LinkNode<Type> *top;
};
template <class Type>
void LinkedStack<Type>::Push(const Type& item)
{
top=new LinkNode<Type>(item,top);
assert(top!=NULL);
};
template <class Type>
bool LinkedStack<Type>::Pop(Type& item)
{
if (IsEmpty()==true)
return false;
LinkNode<Type> *p=top;
top=top->link;
item=p->data;delete p;
return true;
};
template <class Type> bool
bool LinkedStack<Type>::GetTop(Type& item)const
{
if (IsEmpty()==true) return false;
item=top->data;
return true;
};
void main()
{
int number,select=6,i;
char s;
// cout<<"\n请输入栈的大小:"<<endl;
// cin>>size;
LinkedStack<char> stack;
while(select!=5)
{
cout<<"\n\t\t\t************操作菜单*****************\n";
cout<<"\t\t\t\t 1 入栈"<<endl;
cout<<"\t\t\t\t 2 出栈"<<endl;
cout<<"\t\t\t\t 3 取栈顶元素"<<endl;
cout<<"\t\t\t\t 4 栈中元素个数"<<endl;
cout<<"\t\t\t\t 5 退出"<<endl;
cout<<"\t\t\t************请选择序号*****************\n";
cin>>select;
switch(select)
{
case 1:
cout<<"请输入一个字符串并以.结束"<<endl;
cin>>s;
while(s!='.')
{
stack.Push(s);
cin>>s;
}
break;
case 2:
cout<<"请输入出栈字符数:";
cin>>number;
cout<<"\n出栈元素依次为:";
for(i=0;i<number;i++){
if (stack.Pop(s))
cout<<s<<" ";}
break;
case 3:
if (!stack.GetTop(s)){cout<<"栈空"<<endl;break;}
cout<<"栈顶元素为:"<<Stack. GetTop();
break;
case 4:
cout<<"栈中元素个数为:"<<Stack.getSize( );
break;
case 5:
break;
}
}
cout<<"谢谢使用"<<endl;
}