顺序栈的进栈,出栈。注意和顺序表的区别,倒序输出

#include

typedef struct {

int data[5];

int top;

}stack; 

void push(stack &l){

int i,a;

for(i=0;i<5;i++){

printf("输入");

scanf("%d",&a);

++(l.top);

l.data[l.top]=a ;

}

}

//特别注意顺序栈输出的时候和 顺序表的区别:栈倒序输出,顺序表正序输出;注意判断条件 

void pop(stack l){

if(l.top==-1){

printf("0");

    }

else {

while(l.top!=-1){

printf("%d",l.data[l.top]);

printf("\n");

--l.top;

}

    }

}

int main(){

stack L;

L.top=-1;

push(L); 

printf("输出长度") ;

printf("%d",L.top) ;

printf("\n");

printf("输出栈 ") ;

pop(L);

return 0;

}

顺序栈的进栈,出栈。注意和顺序表的区别,倒序输出
 

猜你喜欢

转载自blog.csdn.net/ganghaodream/article/details/88092167