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

}

ZJI(月付450元),香港华为云线路服务器、E3服务器起

ZJI发布了9月份促销信息,针对香港华为云线路物理服务器华为一型提供立减300元优惠码,优惠后香港华为一型月付仅450元起。ZJI是原来Wordpress圈知名主机商家:维翔主机,成立于2011年,2018年9月更名为ZJI,提供中国香港、台湾、日本、美国独立服务器(自营/数据中心直营)租用及VDS、虚拟主机空间、域名注册等业务,商家所选数据中心均为国内访问质量高的机房和线路,比如香港阿里云、华为...

酷锐云香港(19元/月) ,美国1核2G 19元/月,日本独立物理机,

酷锐云是一家2019年开业的国人主机商家,商家为企业运营,主要销售主VPS服务器,提供挂机宝和云服务器,机房有美国CERA、中国香港安畅和电信,CERA为CN2 GIA线路,提供单机10G+天机盾防御,提供美国原生IP,支持媒体流解锁,商家的套餐价格非常美丽,CERA机房月付20元起,香港安畅机房10M带宽月付25元,有需要的朋友可以入手试试。酷锐云自开业以来一直有着良好的产品稳定性及服务态度,支...

SpinServers(月89美元) 2*e5-2630L v2,美国独立服务器

SpinServers服务商也不算是老牌的服务商,商家看介绍是是2018年成立的主机品牌,隶属于Majestic Hosting Solutions LLC旗下。商家主要经营独立服务器租用和Hybrid Dedicated服务器等,目前包含的数据中心在美国达拉斯、圣何塞机房,自有硬件和IP资源等,商家还自定义支持用户IP广播到机房。看到SpinServers推出了美国独服的夏季优惠促销活动,最低月...

99xxx为你推荐
淘宝收费淘宝交易收取的费用是多少深圳公交车路线深圳公交车路线1433端口如何打开SQL1433端口网站联盟网盟跟b2b平台有什么区别直播加速请问哪种播放器的可以播放加速,并且可以保存godaddyGO DADDY服务器空间域名怎么样qq怎么发邮件怎样在QQ上发送邮件?开机滚动条开机滚动条要很长时间怎么解决?安装迅雷看看播放器怎样安装迅雷看看播放器网络广告投放网络广告投放有哪些技巧?
泛域名 最新代理服务器ip 谷歌域名邮箱 西安服务器 电影服务器 mach5 流媒体服务器 paypal认证 美国仿牌空间 permitrootlogin shopex空间 directadmin 网站实时监控 云图标 web服务器架设 hostloc 双十一秒杀 129邮箱 网络空间租赁 免费智能解析 更多