|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 风中醉柳 于 2014-5-6 19:43 编辑
谁能帮我看下bug存在哪里....谢谢咯
#include<stdio.h>
#include<stdlib.h>
typedef int Emptype;
struct L_stack
{
Emptype data;
struct L_stack * next;
}StackSize;
typedef struct L_stack *Ptr;
typedef Ptr hStack;
hStack initstack()
{
hStack sBottom;
sBottom=(hStack )malloc(sizeof(StackSize));
if(!sBottom)
return NULL;
sBottom->next=NULL;
return sBottom;
}
void push(hStack s,Emptype a)
{
hStack add;
add=(hStack )malloc(sizeof(StackSize));
if(!add)
printf("stack NO space\n");
add->data=a;
add->next=s->next;
s->next=add;
}
Emptype pop(hStack s)
{
if(!s)
return 0;
hStack r=s;
Emptype io;
io=s->data;
s=s->next;
free(r);
return io;
}
void DestoryStack(hStack s)
{
hStack r;
if(!s)
printf("stack NO start\n");
while(s)
{
r=s;
s=s->next;
free(r);
}
}
int main(void)
{
hStack q=initstack(),S;
int i;
S=q->next;
for(i=0;i<=5;i++)
push(S,i);
for(i=0;i<5;i++)
printf("%d ",pop(S));
printf("\n");
}
|
|