数据结构实验程序参考

2026/1/27 15:09:50

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);


数据结构实验程序参考.doc 将本文的Word文档下载到电脑
搜索更多关于: 数据结构实验程序参考 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219