C++的入栈出栈问题

yly11 yly11 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#define size 100
typedef struct sqst
{ int data[size];
int top;
}stack;
int n;
void create(stack * &sq)
{
sq=(stack *)malloc(sizeof(stack));
sq->top=0;
int x;
cout<<"gwshu:";
cin>>n;
for(int i=1;i<=n;i++)
{cin>>x;
sq->data[sq->top]=x;
sq->top++;}

}


insert(int x,stack * sq)
{ if(sq->top==size-1)
cout<<"over!";
else
{ sq->top++;
sq->data[sq->top]=x;
return 1;
}

}

gettop(stack * sq,int &x)
{ if (sq->top==-1)
return 0;
else
{ x=sq->data[sq->top];
sq->top--;
cout<<x;
return 1;
}
}





void main()
{ stack * sq;
create(sq);

int x=56;
insert(x,sq);
int i=1;
while (i<=(n+1))
gettop(sq,x);
}



为什么不能显示入栈后的结果?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
yly11
C++ 语言 65,214 成员 250,514 内容