请问哪错了??
#include <stdio.h>#include <malloc.h>
#include <stdlib.h>
typedef struct node
{
int date;
struct node * pnext;
}NODE,* PNODE;
typedef struct stack
{
PNODE ptop;
PNODE pbottom;
}STACK,* PSTACK;
void init (PSTACK );
void push (PSTACK,int);
void traverse (PSTACK);
int main(void)
{
stack s;
init (&s);//目的是造出一个空栈
push (&s,1);//压栈
push (&s,2);
push (&s,3);
traverse (&s);//遍历输出
return ;
}
void init (PSTACK ps )
{
ps->ptop = (PNODE)malloc(sizeof(NODE));
if (NULL != ps->ptop)
{
printf("分配失败\n");
exit(-1);
}
else
{
ps->pbottom = ps->ptop;
ps->pbottom->pnext = NULL;
}
}
void push (PSTACK ps,int val)
{
PNODE pnew = (PNODE)malloc(sizeof(NODE));
pnew->date = val;
pnew->pnext = ps->ptop;
ps->ptop = pnew;
}
void traverse (PSTACK ps)
{
PNODE p = ps->ptop;
while (p != ps->pbottom)
{
printf("%d",p->date);
p = p->pnext;
}
printf("\n");
return;
}