配对数据结构实验4_99XXX

99xxx  时间:2021-02-22  阅读:()

《数据结构》实验报告

实验序号 4 实验项目名称栈的操作

附源程序清单

1.

#include<iostream>

#define MaxSize 100using namespace std;typedef char ElemType;type de f s truct

{

ElemType data[MaxSize] ;int top;

}S qStack;void InitStack(SqStack*st)//初始化栈

{st->top=-1;

}int StackEmpty(SqStack*st) //判断栈为空{if(st->top==-1)return 0;//为空elsereturn-1;//不为空

}void Push(SqStack*st,ElemType x) //元素进栈{if(st->top==MaxSize-1)

{printf("栈上溢出!\n");

}else

{st->top++; //移动栈顶位置st->data[st->top]=x; //元素进栈

}

}void Pop(SqStack*st,ElemType&e) //出栈{if(st->top==-1)

{printf("栈下溢出\n");

}else

{e=st->data[st->top] ; //元素出栈st->top--; //移动栈顶位置}

}int main()

{

SqStack L;

SqStack*st=&L;

ElemType c;int i;

InitStack(st);printf("输入回车结束入栈");while((c=getchar())!='\n')

{if(c=='(')

Pu s h(st,c);if((i=StackEmpty(s t))==-1)

{if(c==')')

Pop(st,c);

}if(c==')'&&(i=StackEmpty(st))==0){printf("右括号多出,配对失败");goto loop;

}

}if(StackEmpty(st)==-1)printf("左括号多出,配对失败");elseprintf("配对成功");loop:return 0;

}

2.

#include<iostream>

#define MaxSize 100using namespace std;typedef int ElemType;type de f s truct

{

ElemType data[MaxSize] ;int top;

}S qStack;void InitStack(SqStack*st)

{st->top=-1;

}int StackEmpty(SqStack*st)

{return(st->top=-1);

}void Push(SqStack*st,ElemType *x,int k){int i;for(i=1;i<k;i++)

{if(st->top==MaxSize-1)

{printf("栈上溢出");

}else

{st->top++;st->data[st->top]=x[i-1];printf("%d\n",st->data[st->top]);}

}

}void Pop(SqStack*st,ElemType&e,int k){int i;for(i=1;i<k;i++)

{if(st->top==-1)

{printf("栈下溢出");

}else

{e=st->data[st->top] ;printf("%d\n",e);st->top--;

}

}

}int main()

{

SqStack L;

SqStack*st=&L;

ElemType e;

ElemType num[9]={1,2,3,4,5,6,7,8,9};InitStack(st);printf("入栈元素是:\n");

Pu s h(st,nu m,10);printf("出栈元素是:\n");

Pop(st,e,10);return 0;

}

3.

#include<iostream>

#include<stack>using namespace std;int main()

{char a,i;stack<char>s;while((a=getchar())!='\n')

{

switch(a)

{case'(':s.pu s h(a);//入栈continue;case'[':s.pu s h(a);continue;case')':if(!s.empty())

{if(s.top()=='(')

{s.pop(); //出栈continue;

}else

{printf("配对失败1");goto loop;

}

}case']':if(!s.empty())

{if(s.top()=='[')

{s.pop(); //出栈continue;

}else

{printf("配对失败2");goto loop;

}s.pop(); //出栈}

}

}if(s.e mpty())

{printf("配对成功");

}else

{printf("配对失败3");}loop:return 0;

}

腾讯云爆款秒杀:1C2G5M服务器38元/年,CDN流量包6元起

农历春节将至,腾讯云开启了热门爆款云产品首单特惠秒杀活动,上海/北京/广州1核2G云服务器首年仅38元起,上架了新的首单优惠活动,每天三场秒杀,长期有效,其中轻量应用服务器2G内存5M带宽仅需年费38元起,其他产品比如CDN流量包、短信包、MySQL、直播流量包、标准存储等等产品也参与活动,腾讯云官网已注册且完成实名认证的国内站用户均可参与。活动页面:https://cloud.tencent.c...

Hostodo美国独立日优惠套餐年付13.99美元起,拉斯维加斯/迈阿密机房

Hostodo又发布了几款针对7月4日美国独立日的优惠套餐(Independence Day Super Sale),均为年付,基于KVM架构,采用NVMe硬盘,最低13.99美元起,可选拉斯维加斯或者迈阿密机房。这是一家成立于2014年的国外VPS主机商,主打低价VPS套餐且年付为主,基于OpenVZ和KVM架构,产品性能一般,支持使用PayPal或者支付宝等付款方式。商家客服响应也比较一般,推...

零途云月付31.9元起,香港cn2 gia线路

零途云是一家香港公司,主要产品香港cn2 gia线路、美国Cera线路云主机,美国CERA高防服务器,日本CN2直连服务器;同时提供香港多ip站群云服务器。即日起,购买香港/美国/日本云服务器享受9折优惠,新用户有优惠码:LINGTUYUN,使用即可打折。目前,零途云还推出性价比非常高香港多ip站群云服务器,有需要的,可以关注一下。零途云优惠码:优惠码:LINGTUYUN (新用户优惠,享受9折优...

99xxx为你推荐
找不到光驱找不到光驱,光盘,怎么办96155北京的住房公积金贷款不能打印还款凭证吗, 给96155打电话,他们说没这项业务,让问问贷款中心51自学网站网上自学网站有哪些?最好是免费的,我想学习网页设计无线路由器限速设置路由器里面限速参数如何设置?邮箱打不开怎么办126邮箱打不开怎么办渗透测试网站渗透测试怎么做?网易公开课怎么下载如何将网易公开课下载到电脑上?数据库损坏数据库坏了怎么办怎么升级ios6iPad怎么升级到iOS6正式版?如何快速收录谁知道怎么快速被搜索引擎快速收录啊?
域名服务器上存放着internet主机的 hostigation 回程路由 新站长网 java空间 京东商城0元抢购 秒杀预告 服务器干什么用的 umax120 t云 英国伦敦 免费的域名 lamp架构 如何登陆阿里云邮箱 阿里云邮箱申请 石家庄服务器 google搜索打不开 建站技术 时间服务器 web服务器 更多