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

}

spinservers春节优惠:$149/月10Gbps圣何塞服务器-2*E5-2630Lv3 CPU,256G内存,2*1.6T SSD硬盘

spinservers是Majestic Hosting Solutions LLC旗下站点,商家提供国外服务器租用和Hybrid Dedicated等产品,数据中心包括美国达拉斯和圣何塞机房,机器默认10Gbps端口带宽,高配置硬件,支持使用PayPal、信用卡、支付宝或者微信等付款方式。农历春节之际,商家推出了几款特别促销配置,最低双路E5-2630Lv3机器每月149美元起,下面列出几款机器...

7月RAKsmart独立服务器和站群服务器多款促销 G口不限量更低

如果我们熟悉RAKsmart商家促销活动的应该是清楚的,每个月的活动看似基本上一致。但是有一些新品或者每个月还是有一些各自的特点的。比如七月份爆款I3-2120仅30美金、V4新品上市,活动期间5折、洛杉矶+硅谷+香港+日本站群恢复销售、G口不限流量服务器比六月份折扣力度更低。RAKsmart 商家这个月依旧还是以独立服务器和站群服务器为主。当然也包括有部分的低至1.99美元的VPS主机。第一、I...

台湾CN2云服务器 2核2G 5M 5IP 台湾物理服务器 E5x2 64G 20M 5IP

提速啦(www.tisula.com)是赣州王成璟网络科技有限公司旗下云服务器品牌,目前拥有在籍员工40人左右,社保在籍员工30人+,是正规的国内拥有IDC ICP ISP CDN 云牌照资质商家,2018-2021年连续4年获得CTG机房顶级金牌代理商荣誉 2021年赣州市于都县创业大赛三等奖,2020年于都电子商务示范企业,2021年于都县电子商务融合推广大使。资源优势介绍:Ceranetwo...

99xxx为你推荐
安装迅雷看看播放器迅雷看看不能播放,说我尚未安装迅雷看看播放器ios系统iOS系统是什么iphone6上市时间苹果6什么时候出来三星s8什么时候上市三星s8什么时候上市 三星s8上市时间微信电话本怎么用微信电话本好用吗去鼠标加速度去鼠标加速到底有什么好处.......怎么在图片上写文字怎么才能在图片上写字呢手工杀毒蠕虫病毒怎么手工杀毒购买流量买流量怎么买淘宝软文范例淘宝上写软文的技巧
武汉域名注册 sharktech arvixe inmotionhosting mediafire下载工具 韩国电信 密码泄露 info域名 京东云擎 parseerror 国外免费空间 免费网络电视 双11秒杀 qq对话框 in域名 华为云服务登录 四川电信商城 空间登录首页 东莞idc 数据库空间 更多