2301_77181217 2023-04-29 12:52 采纳率: 50%
浏览 29
已结题

大家好,我在程序上面没有思路解答这个问题

img


大一新生,编程题对我来说很有难度,没有思路解答,可以提供一点帮助吗,谢谢大家
(上一次的解答对我有非常大的帮助)

  • 写回答

3条回答 默认 最新

  • qzjhjxj 2023-04-29 13:56
    关注

    这是一链队列代码,初始化、进队、出队等功能都有了,输出队列所有数据元素的代码留给题主试着写写,供参考:

    #include <stdio.h>
    #include <stdlib.h>
    #include <crtdbg.h>
    
    #define MAXSIZE 1024
    #define OVERFLOW -2
    #define OK 1
    #define ERROR 0
    typedef int QElemType;
    typedef struct QNode{
        QElemType data;
        struct QNode* next;
    }QNode, * QueuePtr;
    typedef struct
    {
        QueuePtr front;//队头指针
        QueuePtr rear; //队尾指针
    }LinkQueue;
    
    void InitQueue(LinkQueue& Q)//构造一个队列
    {
        Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
        if (!Q.front) exit(OVERFLOW);
        Q.front->next = Q.rear->next = NULL;
        return;
    }
    
    void EnQueue(LinkQueue& Q, QElemType e)// 进队函数
    {
        QNode* p;
        p = (QueuePtr)malloc(sizeof(QNode));
        if (!p) exit(OVERFLOW);
        p->data = e;
        p->next = NULL;
        if (!Q.front->next)
            Q.front->next = p;
        else
            Q.rear->next = p;
        Q.rear = p;
        return;
    }
    
    void DeQueue(LinkQueue& Q, QElemType &e)// 出队函数
    {
        if (!Q.front->next) {
            e = -999;
            return;
        }
        QueuePtr p = Q.front->next;
        e = p->data;
        Q.front->next = p->next;
        free(p);
        return;
    }
     
    void DestroyQueue(LinkQueue& Q)//销毁队列
    {
        while (Q.front)
        {
            Q.rear = Q.front->next;
            free(Q.front);
            Q.front = Q.rear;
        }
        return;
    }
     
    int main()
    {
        int e;
        LinkQueue Q;
    
        InitQueue(Q);
    
        EnQueue(Q, 8);
        EnQueue(Q, 10);
     
        DeQueue(Q, e);
        printf("%d\n", e);
     
        DeQueue(Q, e);
        printf("%d\n", e);
     
        DeQueue(Q, e);
        printf("%d\n", e);
     
        DestroyQueue(Q);
        return 0;
    }
    
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月30日
  • 创建了问题 4月29日

悬赏问题

  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥50 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大
  • ¥15 使用spss做psm(倾向性评分匹配)遇到问题
  • ¥20 vue+UEditor附件上传问题
  • ¥15 想做个WPS的自动化代码,不知道能做的起不。
  • ¥15 uniApp,生成安卓安卓包后,黑暗主题中间内容不生效,底部导航正常
  • ¥15 斯坦福自动漂移非线性模型反解