栈的入栈出栈操作

来源:互联网 发布:移动基站数据库 编辑:程序博客网 时间:2024/06/06 21:37
#include <stdio.h>#define max 26char stack[max];int top=0;int push(char x){    if(top>=max)        return 1;    stack[top++]=x;    return 0;}int pop(){    if(top==0)        return 1;    top=top-1;    return 0;}int main(){    push('a');    push('b');    push('c');    push('d');    pop();    int i=top-1;//注意要令i=top-1,因为每次入栈后,top都会指向栈顶之上的那个元素    while(i>=0)    {        printf("%c ",stack[i--]);    }}
                                             
0 0