数据结构实验代码 包括链表、二叉排序树等……
数据结构实验代码,包括链表、二叉排序树等…… 因数分解少传了个头文件: 补充如下: template class Stack{ struct Node{ Item data; Node* next; }; Node* pTop; public: Stack(); ~Stack(); void push(Item x); Item pop(); Item top(); bool isEmpty(); }; template Stack::Stack():pTop(NULL){ } template Stack::~Stack(){ while(pTop){ Node*p=pTop; pTop=pTop->next; delete p; } } template void Stack::push(Item x){ Node* p=new Node; p-& gt;data=x; p->next=pTop; pTop=p; } template Item Stack::pop(){ if(!pTop) return NULL; Item tmp=pTop->data; Node *p=pTop; pTop=pTop->next; delete p; return tmp; } template Item Stack::top(){ if(!pTop) return NULL; return pTop->data; } template bool Stack::isEmpty(){ return pTop==NULL; } gt;data=x; p->next=pTop; pTop=p; } template Item Stack::pop(){ if(!pTop) return NULL; Item tmp=pTop->data; Node *p=pTop; pTop=pTop->next; delete p; return tmp; } template Item Stack::top(){ if(!pTop) return NULL; return pTop->data; } template bool Stack::isEmpty(){ return pTop==NULL; }