请各位朋友帮我看看!!我这段代码到底是哪出了问题。
我在实现出栈的时候为什么会失败啊
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef int datatype;
typedef struct stackline
{
struct stackline * next;
datatype data;
}stack;
void initstack(stack * top)
{
top = NULL;
}
void push(stack * top, datatype x )
{
stack * s = (stack *)malloc(sizeof(stack));
s -> data = x;
s -> next = top;
top = s;
}
int pop(stack * top, datatype * ptr)
{
stack * p = top;
if (top == NULL)
{
printf("faled");
return 0;
}
* ptr = top -> data;
top = top -> next;
free(p);
return 1;
}
int main()
{
datatype a = 15,b = 16,c = 17;
stack * top = NULL;
datatype *ptr = 0;
initstack(top);
push(top, a);
pop(top, ptr);
return 0;
}
****