配对数据结构实验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;

}

wordpress通用企业主题 wordpress高级企业自适应主题

wordpress高级企业自适应主题,通用型企业展示平台 + 流行宽屏设计,自适应PC+移动端屏幕设备,完美企业站功能体验+高效的自定义设置平台。一套完美自适应多终端移动屏幕设备的WordPress高级企业自适应主题, 主题设置模块包括:基本设置、首页设置、社会化网络设置、底部设置、SEO设置; 可以自定义设置网站通用功能模块、相关栏目、在线客服及更多网站功能。点击进入:wordpress高级企业...

WHloud Date鲸云数据($9.00/月), 韩国,日本,香港

WHloud Date(鲸云数据),原做大数据和软件开发的团队,现在转变成云计算服务,面对海内外用户提供中国大陆,韩国,日本,香港等多个地方节点服务。24*7小时的在线支持,较为全面的虚拟化构架以及全方面的技术支持!官方网站:https://www.whloud.com/WHloud Date 韩国BGP云主机少量补货随时可以开通,随时可以用,两小时内提交退款,可在工作日期间全额原路返回!支持pa...

半月湾hmbcloud升级500Mbps带宽,原生VPS,$4.99/月

关于半月湾HMBCloud商家之前也有几篇那文章介绍过这个商家的产品,对于他们家的其他产品我都没有多加留意,而是对他们家的DC5机房很多人还是比较喜欢的,这个比我们有些比较熟悉的某商家DC6 DC9机房限时,而且半月湾HMBCloud商家是相对便宜的。关于半月湾DC5机房的方案选择和介绍:1、半月湾三网洛杉矶DC5 CN2 GIA同款DC6 DC9 1G内存 1TB流量 月$4.992、亲测选择半...

99xxx为你推荐
优酷路由宝怎么赚钱优酷路由宝整的可以赚钱吗?可以赚多少?bbsxp怎么用 CUTEFTP上传BBSXP到FTP服务器人人时光机求徐智勇的时光机的歌词,百度上全是周杰轮跟五月天的,我要粤语啊网站联盟网盟跟b2b平台有什么区别宕机宕机是什么意思?微信怎么看聊天记录微信怎样查询聊天记录请客网有没有请客吃饭类的网站呢?哪个比较专业呢?有没有官方的呢?ncsetting为什么安装NCSettings没有反应啊,那个开关是默认开的啊,可通知栏没有这个啊?qq签名设置QQ个性签名设置上传文件怎样把文件上传到文件中转站
北京主机租用 美国php空间 服务器架设 网通ip 申请个人网站 idc资讯 电信虚拟主机 重庆双线服务器托管 常州联通宽带 创建邮箱 web服务器是什么 电信网络测速器 云服务器比较 申请免费空间 创速 香港博客 ipower 带宽测速 热云 ddos攻击 更多