小编gme*_*h94的帖子

使用c中的链接列表进行排队

在编译期间,此代码不会出错,但代码会突然停止.据我说,问题在于声明的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)

c queue pointers linked-list

1
推荐指数
1
解决办法
2102
查看次数

标签 统计

c ×1

linked-list ×1

pointers ×1

queue ×1