C语言实现栈

来源:互联网 发布:手机注册淘宝店铺 编辑:程序博客网 时间:2024/06/02 17:29
#include<stdio.h>#include<string.h>int Stack[1000],top;void push(int n)//入栈{    Stack[++top]=n;}int popstack() //出栈{   return Stack[top--];}int main(){    top=-1;    int n,i;    while(scanf("%d",&n)!=EOF)    {        for( i=0; i<n; i++)        {            int s;            scanf("%d",&s);            push(s);        }        int m;        scanf("%d",&m);        for(i=0; i<m; i++)        {   int x;            if(top<0)                break;                x=popstack();            printf("%d\n",x);        }    }    return 0;}

0 0
原创粉丝点击