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

}

华纳云E5处理器16G内存100Mbps688元/月

近日华纳云商家正式上线了美国服务器产品,这次美国机房上线的产品包括美国云服务器、美国独立服务器、美国高防御服务器以及美国高防云服务器等产品,新产品上线华纳云推出了史上优惠力度最高的特价优惠活动,美国云服务器低至3折,1核心1G内存5Mbps带宽低至24元/月,20G ddos高防御服务器低至688元/月,年付周期再送2个月、两年送4个月、三年送6个月,终身续费同价,有需要的朋友可以关注一下。华纳云...

ATCLOUD.NET-OVH海外高防云主机,采用KVM架构,稳定安全且便宜好用,仅3刀起

官方网站:点击访问ATCLOUD.NET官网优惠码:目前提供Cloud VPS与Storage VPS两款产品的六折优惠活动(续费同价,截止至2021年5月31日)优惠码:UMMBPBR20Z活动方案:一、型号CPU内存磁盘流量优惠价格购买链接VPS-1GB0.5×2.6+GHz1GB20GB1TB$3立即购买VPS-2GB1×2.6+GHz2GB50GB2TB$6立即购买VPS-4GB2×2.6...

LOCVPS新上韩国KVM,全场8折,2G内存套餐月付44元起_网络传真服务器

LOCVPS(全球云)发布了新上韩国机房KVM架构主机信息,提供流量和带宽方式,适用全场8折优惠码,优惠码最低2G内存套餐月付仅44元起。这是一家成立较早的国人VPS服务商,目前提供洛杉矶MC、洛杉矶C3、和香港邦联、香港沙田电信、香港大埔、日本东京、日本大阪、新加坡、德国和荷兰等机房VPS主机,基于KVM或者XEN架构。下面分别列出几款韩国机房KVM主机配置信息。韩国KVM流量型套餐:KR-Pl...

99xxx为你推荐
免费建站系统国内最好的自助建站系统?ios7固件下载ios 7及以上固件请在设备上点“信任”在哪点?怎么点亮qq空间图标怎样点亮qq空间的图标怎么升级ios6苹果IOS5怎么升级IOS6版本ejb开发什么是EJB?它是干什么的?和JAVA,JSP有关系吗?他们各有什么特点和用途?bluestack安卓模拟器bluestacks怎么用?什么是云平台什么是云系统?网站优化方案网站优化方法有哪些blogcnblogcn网页无法正常显示,直接跳转http://www.7t7t.com/7?网站排名靠前如何使网站排名靠前?
虚拟空间免费试用 万网域名 3322动态域名注册 大庆服务器租用 看国外视频直播vps 便宜域名 gomezpeer 网络星期一 抢票工具 网通服务器ip 镇江联通宽带 e蜗牛 dd444 建立邮箱 phpmyadmin配置 免费高速空间 lick photobucket ssl加速 江苏双线 更多