user-0 提问: 大佬们帮忙看下哪里错了

回复:
user: user-1
content: C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html C和C++算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html

user: user-0
content: 引用 1 楼 自信男孩的回复:#include<stdio.h> #include<stdlib.h>  #define OVERLOW -2 #define ERROR 0 #define OK 1  typedef int Status; typedef float QElemType;  typedef struct QLNode{     QElemType data;     struct QLNode *next; }QLNode, *QueuePtr; typedef struct {     QueuePtr front;     QueuePtr rear; }LinkQueue;  //创建空队列 Status InitQueue(LinkQueue &Q) {     /*     Q.front = Q.rear = (QueuePtr)malloc(sizeof(QLNode));     if(!Q.front)     {         exit(OVERLOW);     }      //Q.front = NULL;     Q.front->next = NULL;     */     Q.front = Q.rear = NULL;     return OK; } Status ClearQueue(LinkQueue &Q); //销毁队列 Status DestoryQueue(LinkQueue &Q) {     ClearQueue(Q);     /*     while(Q.front)     {         Q.rear = Q.front->next;         free(Q.rear);         Q.front = Q.rear;     }     */     return OK; } //插入元素e为Q的新的队尾元素 Status EnQueue(LinkQueue &Q, QElemType e) {     QueuePtr p;     printf("请输入e的值\n");     scanf("%f", &e);     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     p->data = e;     p->next = NULL;      if (Q.rear == NULL) {         Q.rear = Q.front = p;     } else {         Q.rear->next = p;         Q.rear = p;     }     /*     p->data = e;     p->next =NULL;     Q.rear->next = p;     Q.rear = p;     */     return OK; } //删除Q的对头元素，用e带回 Status DeQueue(LinkQueue &Q, QElemType &e) {     QueuePtr p;      if (Q.front == NULL)         return ERROR;      if (Q.front == Q.rear) {         e = Q.front->data;         p = Q.front;         Q.front = Q.rear = NULL;         free(p);         return OK;     }     e = Q.front->data;     p = Q.front;      Q.front = Q.front->next;     free(p);     return OK;      /*     QueuePtr p;     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     if(Q.front == Q.rear)     {         return ERROR;     }     p = Q.front->next;     e = p->data;     Q.front->next = p->next;     if (p == Q.rear) //当删除最后一个元素时，尾指针可能没有指向     {         Q.rear = Q.front;     }     free(p);     */     return OK; } //清空队列 Status ClearQueue(LinkQueue &Q) {     QueuePtr p, q;      p = Q.front;      while (p) {         q = p->next;         free(p);         p = q;     }     Q.front = Q.rear = NULL;      /*     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     while(!Q.rear)     {         p = Q.front->next;         Q.front->next = p->next;         free(p);     }     Q.rear = Q.front;     */     return OK; } //计算队列的长度 Status QueueLength(LinkQueue Q) {     QueuePtr p;     int i = 0;      p = Q.front;      while (p) {         i++;         p = p->next;     }      /*     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     Status i = 1;     p = Q.front->next;     while(p != Q.rear)     {         p = p->next;         i++;     }     */     return i; } //用e返回Q的头部元素 Status GetHead(LinkQueue Q, QElemType &e) {     if (!Q.front)         return ERROR;      e = Q.front->data;     /*     if(Q.front == Q.rear)     {         return ERROR;     }     e = Q.front->next->data;     */     return OK; }  //显示队列 Status VisitQueue(LinkQueue Q) {     QueuePtr p;      p = Q.front;      while (p) {         printf("%.1f ", p->data);         p = p->next;     }     printf("\n");      /*     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     p = Q.front->next;     while(p != Q.rear->next)     {         printf("%f", p->data);         p = p->next;     }     */     return 0; } int main() {     LinkQueue Q;     QElemType e;     Status flag;     int len;     while(1)     {         printf("****************************\n");         printf("********队列操作系统********\n");         printf("1.创建空队列                \n");         printf("2.插入元素e为Q的新的队尾元素\n");         printf("3.删除Q的对头元素，用e带回  \n");         printf("4.清空队列                  \n");         printf("5.计算队列的长度            \n");         printf("6.用e返回Q的头部元素        \n");         printf("7.显示队列                  \n");         printf("8.销毁队列                  \n");         printf("请选择功能序号：\n");         scanf("%d", &flag);         switch(flag)         {             case 1: InitQueue(Q);                     break;             case 2: EnQueue(Q, e);                     break;             case 3: DeQueue(Q, e);                     break;             case 4: ClearQueue(Q);                     break;             case 5: len = QueueLength(Q);                     printf("Queue's length: %d\n", len);                     break;             case 6: GetHead(Q, e);                     printf("head data: %.1f\n", e);                     break;             case 7: VisitQueue(Q);                     break;             case 8: DestoryQueue(Q);                     break;         }//switch     }//while     return OK; }  供参考～  除了代码问题之外，架构设计的也有点问题，初始化队列，不应该放在选择项里，而是放在进入循环之前的操作； 清除队列和销毁队列其实是一个意思～ 谢谢，我是大一学生，术语懂得不多，谢大佬指点

user: user-2
content: #include<stdio.h> #include<stdlib.h>  #define OVERLOW -2 #define ERROR 0 #define OK 1  typedef int Status; typedef float QElemType;  typedef struct QLNode{     QElemType data;     struct QLNode *next; }QLNode, *QueuePtr; typedef struct {     QueuePtr front;     QueuePtr rear; }LinkQueue;  //创建空队列 Status InitQueue(LinkQueue &Q) {     /*     Q.front = Q.rear = (QueuePtr)malloc(sizeof(QLNode));     if(!Q.front)     {         exit(OVERLOW);     }      //Q.front = NULL;     Q.front->next = NULL;     */     Q.front = Q.rear = NULL;     return OK; } Status ClearQueue(LinkQueue &Q); //销毁队列 Status DestoryQueue(LinkQueue &Q) {     ClearQueue(Q);     /*     while(Q.front)     {         Q.rear = Q.front->next;         free(Q.rear);         Q.front = Q.rear;     }     */     return OK; } //插入元素e为Q的新的队尾元素 Status EnQueue(LinkQueue &Q, QElemType e) {     QueuePtr p;     printf("请输入e的值\n");     scanf("%f", &e);     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     p->data = e;     p->next = NULL;      if (Q.rear == NULL) {         Q.rear = Q.front = p;     } else {         Q.rear->next = p;         Q.rear = p;     }     /*     p->data = e;     p->next =NULL;     Q.rear->next = p;     Q.rear = p;     */     return OK; } //删除Q的对头元素，用e带回 Status DeQueue(LinkQueue &Q, QElemType &e) {     QueuePtr p;      if (Q.front == NULL)         return ERROR;      if (Q.front == Q.rear) {         e = Q.front->data;         p = Q.front;         Q.front = Q.rear = NULL;         free(p);         return OK;     }     e = Q.front->data;     p = Q.front;      Q.front = Q.front->next;     free(p);     return OK;      /*     QueuePtr p;     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     if(Q.front == Q.rear)     {         return ERROR;     }     p = Q.front->next;     e = p->data;     Q.front->next = p->next;     if (p == Q.rear) //当删除最后一个元素时，尾指针可能没有指向     {         Q.rear = Q.front;     }     free(p);     */     return OK; } //清空队列 Status ClearQueue(LinkQueue &Q) {     QueuePtr p, q;      p = Q.front;      while (p) {         q = p->next;         free(p);         p = q;     }     Q.front = Q.rear = NULL;      /*     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     while(!Q.rear)     {         p = Q.front->next;         Q.front->next = p->next;         free(p);     }     Q.rear = Q.front;     */     return OK; } //计算队列的长度 Status QueueLength(LinkQueue Q) {     QueuePtr p;     int i = 0;      p = Q.front;      while (p) {         i++;         p = p->next;     }      /*     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     Status i = 1;     p = Q.front->next;     while(p != Q.rear)     {         p = p->next;         i++;     }     */     return i; } //用e返回Q的头部元素 Status GetHead(LinkQueue Q, QElemType &e) {     if (!Q.front)         return ERROR;      e = Q.front->data;     /*     if(Q.front == Q.rear)     {         return ERROR;     }     e = Q.front->next->data;     */     return OK; }  //显示队列 Status VisitQueue(LinkQueue Q) {     QueuePtr p;      p = Q.front;      while (p) {         printf("%.1f ", p->data);         p = p->next;     }     printf("\n");      /*     p = (QueuePtr)malloc(sizeof(QLNode));     if(!p)     {         exit(OVERLOW);     }     p = Q.front->next;     while(p != Q.rear->next)     {         printf("%f", p->data);         p = p->next;     }     */     return 0; } int main() {     LinkQueue Q;     QElemType e;     Status flag;     int len;     while(1)     {         printf("****************************\n");         printf("********队列操作系统********\n");         printf("1.创建空队列                \n");         printf("2.插入元素e为Q的新的队尾元素\n");         printf("3.删除Q的对头元素，用e带回  \n");         printf("4.清空队列                  \n");         printf("5.计算队列的长度            \n");         printf("6.用e返回Q的头部元素        \n");         printf("7.显示队列                  \n");         printf("8.销毁队列                  \n");         printf("请选择功能序号：\n");         scanf("%d", &flag);         switch(flag)         {             case 1: InitQueue(Q);                     break;             case 2: EnQueue(Q, e);                     break;             case 3: DeQueue(Q, e);                     break;             case 4: ClearQueue(Q);                     break;             case 5: len = QueueLength(Q);                     printf("Queue's length: %d\n", len);                     break;             case 6: GetHead(Q, e);                     printf("head data: %.1f\n", e);                     break;             case 7: VisitQueue(Q);                     break;             case 8: DestoryQueue(Q);                     break;         }//switch     }//while     return OK; }  供参考～  除了代码问题之外，架构设计的也有点问题，初始化队列，不应该放在选择项里，而是放在进入循环之前的操作； 清除队列和销毁队列其实是一个意思～