可以编译,但是没有办法运行
用vs调试,我猜测问题出现在指针初始化上面
(init 函数)
#include<stdio.h>
#include<malloc.h>
typedef struct node
{ struct node *next;
int data;
} QNode;
//
typedef struct aaa
{ QNode *front;
QNode *rear; //指针指向 QNode 类型
}LQueue;
// 初始化
void init (QNode *s,LQueue *L)
{ s= (struct node* )malloc( sizeof(struct node));
L= (LQueue* )malloc( sizeof(LQueue));
s->next=NULL;
L->front=L->rear=(struct node* )malloc( sizeof(struct node)) ;
L->front=L->rear= s;
}
//入队
void push (LQueue *l,int x)
{ QNode *q=NULL;
q= (struct node* )malloc( sizeof(struct node));
q->data=x; q->next=NULL;
l->rear->next=q;
l->rear = q;
}
QNode *pop (QNode *p,LQueue *L,int *x)
{ QNode *s=NULL;
s=L->front;
L->front=L->front->next;
*x = s->data;
free(s);
}
//测试
int main(void)
{ int x=1;int *x1=NULL;
QNode *a = NULL;
LQueue *b =NULL;
init (a,b);
push( b ,x);
// printf("%d",L->rear->data);
}