在编译期间,此代码不会出错,但代码会突然停止.据我说,问题在于声明的createq函数在哪里q->front=q->rear=NULL.它必须初始化.这有什么不对吗?
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
struct node
{
struct node *next;
int data;
};
struct queue
{
struct node *front;
struct node *rear;
};
struct queue *q;
void createq(struct queue *);
struct queue *insert(struct queue *);
struct queue *delete_q(struct queue *);
struct queue *display(struct queue *);
int main()
{
int option;
printf("\tMAIN MENU\n");
printf("\n1. Create\n2. Display\n3. Insert\n4. Delete\n5. Exit\n");
while(option!=5)
{
printf("\nEnter a choice:");
scanf("%d",&option);
switch(option)
{
case 1:
createq(q);
break;
case 2:
q=display(q);
break;
case 3: …Run Code Online (Sandbox Code Playgroud)