鱼C论坛

 找回密码
 立即注册
查看: 2535|回复: 1

队列元素打印不出来是哪错了,求帮助

[复制链接]
发表于 2020-5-5 16:42:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

typedef char ElemType;

typedef struct QNode
{
        ElemType data;
        struct QNode *next;
}QNode,*QueuePrt;

typedef struct
{
        QueuePrt front,rear;
}LinkQueue;

void InitQueue(LinkQueue *q)
{
        q->front=(QueuePrt)malloc(sizeof(QNode));
        if(!q->front)
                exit(0);
        q->front->next=NULL;
}

void InsertQueue(LinkQueue *q,ElemType e)
{
        QueuePrt p;
        p=(QueuePrt)malloc(sizeof(QNode));
        if(!p)
                exit(0);
        p->data=e;
        p->next=NULL;
        q->rear->next=p;
        q->rear=p;
}

void DeleteQueue(LinkQueue *q,ElemType *e)
{
        QueuePrt p;
        if(q->front==q->rear)
                return;
        p=q->front->next;
        *e=p->data;
        q->front->next=p->next;
        if(q->rear==p)
                q->rear=q->front;
        free(p);
}

int main()
{
        ElemType c;
        LinkQueue q;
        InitQueue(&q);
       
        printf("请输入字符串\n");
        scanf("%c",&c);
        while(c != '#')
        {
                InsertQueue( &q, c);
                scanf("%c",&c);
        }
        while(q.front != q.rear)
        {
                DeleteQueue(&q,&c);
                printf("%c",c);
        }
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-5-13 08:48:13 | 显示全部楼层
初始化队列函数中没有交代s->rear的位置
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-22 22:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表