链栈表达式求值Word文件下载.docx

上传人:b****6 文档编号:21743403 上传时间:2023-02-01 格式:DOCX 页数:13 大小:15.23KB
下载 相关 举报
链栈表达式求值Word文件下载.docx_第1页
第1页 / 共13页
链栈表达式求值Word文件下载.docx_第2页
第2页 / 共13页
链栈表达式求值Word文件下载.docx_第3页
第3页 / 共13页
链栈表达式求值Word文件下载.docx_第4页
第4页 / 共13页
链栈表达式求值Word文件下载.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

链栈表达式求值Word文件下载.docx

《链栈表达式求值Word文件下载.docx》由会员分享,可在线阅读,更多相关《链栈表达式求值Word文件下载.docx(13页珍藏版)》请在冰豆网上搜索。

链栈表达式求值Word文件下载.docx

top)

{

next=top;

top=NULL;

}

intSNode:

StackEmpty(SNode*&

t)

return(t==NULL);

Push(SNode*&

top,SElemType&

x)

SNode*p=newSNode;

p->

data=x;

next=top;

top=p;

returnOK;

SElemTypeSNode:

GetTop(SNode*&

if(StackEmpty(top))

returnERROR;

return(top->

data);

pop(SNode*&

e)

p=top;

if(StackEmpty(p))

{returnERROR;

else

{

e=top->

data;

top=top->

next;

delete(p);

returnOK;

}

MakeEmpty(SNode*&

while(top!

=NULL)

Print(SNode*&

intn;

SElemTypea;

cout<

<

"

请输入元素个数:

;

cin>

>

n;

请输入元素:

for(inti=1;

i<

=n;

i++)

cin>

a;

Push(top,a);

Show(SNode*&

SNode*p=top;

while(p)

cout<

p->

p=p->

endl;

Elem_num(SNode*&

intnum=0;

num++;

returnnum;

/*

Delate_end(SNode*&

while(p-next)

delete(p);

*/

End(SNode*&

SNode*p=top;

while(p->

next)

e=p->

Replace_end(SNode*&

*/#include"

*/typedefcharSElemType;

classSNode

public:

SElemTypedata;

SNode*next;

voidInitStack(SNode*&

top);

//初始化一个栈尾指针next与头指针top指向相同的一片区域为NULL

intStackEmpty(SNode*&

t);

//判断栈顶指针是否为空

intPush(SNode*&

x);

//输入一个元素x并加入栈顶

SElemTypeGetTop(SNode*&

//返回类型为SElenType返回值为顶指针所指的data值

intpop(SNode*&

e);

//栈顶元素出栈,地址传递栈顶元素e

intMakeEmpty(SNode*&

//将当前栈置空

voidPrint(SNode*&

voidShow(SNode*&

intElem_num(SNode*&

//返回值为栈中的元素个数

//voidDelate_end(SNode*&

//将栈尾值删除,并将栈尾指针this->

next前移

voidEnd(SNode*&

//得到栈尾data值并返回

//voidReplace_end(SNode*&

//将尾数据替换为SElemType类的x

};

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 英语

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1