第一范文网 - 专业文章范例文档资料分享平台

数据结构_实验三_栈和队列及其应用

来源:用户分享 时间:2025/5/25 0:54:40 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

if(L->next==NULL) return ERROR; e=L->next->data; return OK;

Status StackEmpty(Lq_Stack L){ }

int StackLength(Lq_Stack L){ }

Status DestroyStack(Lq_Stack &L){ }

void Menu(Lq_Stack &L,SElemType e){

//输出菜单选择执行得功能 int select=1; while(select) {

cout<<\————————————\//销毁栈 LqStack *p; while(!L) { } return OK;

L=p; L=L->next; free(p); //计算栈得长度 return L->data; //判断栈就是否为空

if(L->next==NULL){return ERROR;} else return OK;

cout<<\请选择功能\

cout<<\——————1、入栈\cout<<\——————2、出栈\cout<<\——————3、得到顶部数据\cout<<\——————4、判断栈就是否为空\cout<<\——————5、输出栈得长度\cout<<\——————0、退出程序\cout<<\您得选择就是:\cin>>select; switch (select){ case 0:break; case 1:

cout<<\cin>>e; if(push(L,e)){ }

else cout<<\break;

cout<<\

case 2:

if(pop(L,e)){

cout<<\

else cout<<\break;

case 3:

if(GetTop(L,e)){

cout<<\

else cout<<\break;

case 4:

}

}

if(StackEmpty(L)){

cout<<\

else cout<<\break;

case 5: }

cout<<\break;

//Lstack、h

#include #include using namespace std; const int OK=1; const int ERROR=0; typedef int SElemType; typedef int Status; typedef struct LqStack{

SElemType data; struct LqStack *next;

}LqStack,*Lq_Stack;

Status InintStack (Lq_Stack &L);//创建栈 Status push (Lq_Stack &L,SElemType e);//入栈 Status pop (Lq_Stack &L,SElemType &e);//出栈

Status GetTop(Lq_Stack L, SElemType &e);//得到栈顶数据 Status StackEmpty(Lq_Stack L);//判断栈就是否为空 int StackLength(Lq_Stack L);//计算栈得长度 Status DestroyStack(Lq_Stack &L);//销毁栈

void Menu(Lq_Stack &L,SElemType e);//输出菜单选择执行得功能

? 运行结果:

(2)

应用栈得基本操作,实现数制转换(任意进制);;

? 代码部分: //Main、cpp

#include\、h\int main(){ }

int number;

cout<<\要将数值转换为多少进制 \cin>>number; conversion(number); return 0;

SStack、cpp

#include\、h\Status InitStack(SStack &S){

//创建栈

S、dase=(ElemType *)malloc(STACK_INIT_SIZE * sizeof(ElemType)); if (!S、dase) exit(ERROR);

搜索更多关于: 数据结构_实验三_栈和队列及其应用 的文档
数据结构_实验三_栈和队列及其应用.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1foa9704kc9sc9l3ppnv1xep036fj70199z_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top