- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
编写一个程序,现链栈的各种基本运算
软件技术基础试验二
链栈的各种基本运算的实现
班级:
学号:
姓名:
一、实验题目
编写一个程序,实现链栈的各种基本运算,并在此基础上设计一个主程序完成如下功能:
(1)初始化链栈
(2)按指定的元素顺序将多个元素进栈
(3)输出从栈顶到指定位置的元素
(4)判断链栈是否非空
二、实验目的
(1)掌握链栈的基本运算:栈的初始化、进栈、出栈、判断栈的空否。
(2)掌握运用 C 语言上机调试链栈的基本方法。
三、调试通过并正确执行给定功能要求的实验代码
#include stdafx.h
#includestdio.h
#includestdlib.h
struct link
{
char data;
link *next;
};
void inistack(link *top)
{top-next=NULL;}
void push(link *top,int x)
{
link *s;s=new link;
s-data=x;s-next=top-next;top-next=s;
}
int empty(link *top)
{
if(top-next==NULL) return(1);
else return(0);
}
void pop(link *top)
{
link *s;
s=top-next;
printf(%c ,s-data);
if(s!=NULL)
{top-next=s-next;delete(s);}
}
void main()
{
int i=0,j=0,flag,t,length;
char ch,zz[30];
link *top;
FILE *fp;
if((fp=fopen(D:\\a.txt,rt))==NULL)
{printf(cannot open file);}
ch=fgetc(fp);
while(ch!=EOF) //把从文件中读取的字符存放在zz中
{
zz[i]=ch;
ch=fgetc(fp);
i++;
}
fclose(fp);
top=new link;
inistack(top);
printf(请输入链栈长度:);
scanf(%d,length);
for(i=0;ilength;i++)
{
push(top,zz[i]);
}
printf(请输入指定位置:);
scanf(%d,t);
for(j;jt;j++)
{
flag=empty(top);
if(flag==1)
{printf(\n链栈已经为空栈!);break;}
pop(top);
}
}
四、实验结果截图
integrated energy, chemicals and textile Yibin city, are the three core pillars of the industry. In 2014, the wuliangye brand value to 73.58 billion yuan, the citys liquor industry slip to stabilise. Promoting deep development of integrated energy, advanced equipment manufacturing industry, changning district, shale gas production capacity reached 277 million cubic metres, built the countrys first independent high-yield wells and pipelines in the first section, the lead in factory production and supply to the population. 2.1-3 GDP growth figure 2.1-4 Yibin, Yibin city, Yibin city, fiscal revenue growth 2.1.4 topography terrain overall is Southwest, North-Eastern State. Low mountains and hills in the city landscape as the main ridge-and-Vall
文档评论(0)