顺序栈进栈与出栈算法
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
int pop()
{int x;
if(top==-1)
{printf("underflow!\n");
exit(1);
}
else
{x=stack[top];
top--;}
return x;
}
int main()
{int i;
printf("top: ");
scanf("%d",&top);
printf("please put stack:\n");
printf("%d ",stack[i]);
printf("\n");
getch();
}
printf("\n");
printf("please delete three numbers:\n");
for(i=0;i<=top;i++)
printf("%d ",pop());
printf("\n");
printf("here is the result:\n");
for(i=0;i<=top;i++)
#include<stdio.h>
#define maxlen 10
int stack[maxlen];
int top=-1;
void push(int x)
{if(top==maxlen-1)
{printf("overflow!\n");
exit(1);
}பைடு நூலகம்
else{top++;
stack[top]=x;}
for(i=0;i<=top;i++)
scanf("%d",&stack[i]);
push(58);
printf("please put int a number:\n");
printf("58\n");
printf("the result is:\n");
for(i=0;i<=top;i++)
printf("%d ",stack[i]);
int pop()
{int x;
if(top==-1)
{printf("underflow!\n");
exit(1);
}
else
{x=stack[top];
top--;}
return x;
}
int main()
{int i;
printf("top: ");
scanf("%d",&top);
printf("please put stack:\n");
printf("%d ",stack[i]);
printf("\n");
getch();
}
printf("\n");
printf("please delete three numbers:\n");
for(i=0;i<=top;i++)
printf("%d ",pop());
printf("\n");
printf("here is the result:\n");
for(i=0;i<=top;i++)
#include<stdio.h>
#define maxlen 10
int stack[maxlen];
int top=-1;
void push(int x)
{if(top==maxlen-1)
{printf("overflow!\n");
exit(1);
}பைடு நூலகம்
else{top++;
stack[top]=x;}
for(i=0;i<=top;i++)
scanf("%d",&stack[i]);
push(58);
printf("please put int a number:\n");
printf("58\n");
printf("the result is:\n");
for(i=0;i<=top;i++)
printf("%d ",stack[i]);