|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<stdlib.h>
#define MAXSIDE 20
typedef struct {
char stack[MAXSIDE];
int top;
}Sqstack,*Psqstack;
void Inin_stack(Psqstack n_stack)
{
n_stack=(Psqstack)malloc(sizeof(Sqstack));
n_stack->top=-1;
}
int pop_stack(Psqstack n_stack,char e)
{
if(-1==n_stack->top)
return 0;
e=n_stack->stack[n_stack->top];
n_stack->top--;
return 1;
}
void display_stack(Psqstack n_stack)
{
int i;
//for(i=0;i<=n_stack->top;i++)
for(i=n_stack->top;i>=0;i--)
printf("%c",n_stack->stack[i]);
printf("\n");
}
int main(void)
{
Sqstack n_stack;
char stack[MAXSIDE]="i want to love you!";
char e;
int i;
Inin_stack(&n_stack);
for(i=0;stack[i]!='\0';i++)
{
push_stack(&n_stack,stack[i]);
}
display_stack(&n_stack);
}
大哥们,我这个栈为什么不能显示啊?编译没问题啊!!!!5555555555555555555555555555 |
|