//清栈函数
template<class t1>
void linkstack<t1>::clear()
{t1 x;
while(pop(x));
}
//进栈函数
template<class t1>
void linkstack<t1>::push(t1 &x)
{stacknode<t1> *p;
if(top)
{p=new stacknode<t1>;
assert(p);
p->data=x;
p->next=top;
top=p;
}
else
{top=new stacknode<t1>;
assert(top);
top->data=x;
top->next=NULL;
}
height++;}
//出栈函数
template<class t1>
bool linkstack<t1>::pop(t1&x)
{stacknode<t1> *p;
if(height)
{x=top->data;
p=top;
top=top->next;
delete p;
height--;
return true;}
else
return false;
}
int main()
{linkstack<char> a;
char c,d;
cout<<"请输入算式,以#结束"<<endl;
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库数据结构实验报告 堆栈和队列(7)在线全文阅读。
相关推荐: