云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 数据结构实验程序参考

数据结构实验程序参考

  • 62 次阅读
  • 3 次下载
  • 2025/5/1 16:54:51

else {pre=q; q=q->next;}

} p=p->next; } }

3.栈操作

(1)顺序栈 typedef int elemtype; #include \

/* ========menu ======== */ char menu(void) { char ch;

clrscr(); printf(\ printf(\

printf(\ MENU \\n\ printf(\ ===========================\\n\ printf(\ Seqential stack operations\\n\ printf(\ 1. push\\n\ printf(\ 2. pop\\n\ printf(\ 3. get top\\n\ printf(\ 0. exit\\n\

printf(\ ===========================\\n\ printf(\ Choice(0,1,2,3):\ ch=getchar();

return(ch); } main() { SqStack st; int i,flag=1,n,k; char choice; InitStack(&st); do{ choice=menu(); clrscr(); switch (choice)

{ case '1': printf(\ push data=?\

k=Push(&st, n); if(k) printf(\else printf(\getch();break;

case '2': k=Pop(&st,&n);

if(k) printf(\ pop data=%d\\n\else printf(\ The stack is empty.\getch( );break;

case '3': k=GetTop(st, &n);

if(k)printf(\ top data=%d\\n\else printf(\ The stack is empty.\getch( ); break;

case '0': flag=0; }

}while(flag==1);} (2)链栈 #define Max 100 #define elementtype int typedef struct

{ elementtype data[Max]; int top; }stacktype;

void Push(stacktype *s,elementtype x) { if(s->top==Max-1)

{ printf(\ s->top++; s->data[s->top]=x; }

int stackempty(stacktype s) {if(s.top==-1) return(1); else return(0); }

void Pop(stacktype *s,elementtype *e) { if(stackempty(*s))

{ printf(\ else

{ *e=s->data[s->top];

s->top--; } }

void MENU()

{printf(\ printf(\ printf(\ printf(\

printf(\ printf(\} main() { stacktype s; int c; char x, e; s.top=-1; do { MENU(); scanf(\ switch(c)

{case 1:printf(\

scanf(\ Push(&s,x); break; case 2:Pop(&s,&e);

搜索更多关于: 数据结构实验程序参考 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

else {pre=q; q=q->next;} } p=p->next; } } 3.栈操作 (1)顺序栈 typedef int elemtype; #include \/* ========menu ======== */ char menu(void) { char ch; clrscr(); printf(\ printf(\ printf(\ MENU \\n\ printf(\ ===========================\\n\ printf(\ Seqential stack operations\\n\ print

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com