Switch-biu 2022-10-17 21:36 采纳率: 90%
浏览 18
已结题

关于#数据结构#的问题:数据结构 运行结果及报错内容

数据结构


```c
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define MAX_NUM 6

typedef struct{
    int queue[MAX_NUM];
    int front;
    int rear;
    int s;
}Queue_Type;

Queue_Type *p;
 
void InitQueue(Queue_Type *p)
{
    p->front = 0;
    p->rear = 0;
    p->s =0;
}

void OutQueue(Queue_Type *p,int m)
{
    int i,y;
    for(i=1;i<6;i++)
    {
    printf("%d",p->front);
    p->front = p->front % m + 1;
    y=p->queue[p->front - 1];
    if(p->front == p->rear)
    p->s==0;
    }
}

void InQueue(Queue_Type *p,int m)
{
    int x;
    if((p->s==1)&&(p->rear == p->front))
     printf("overflow!\n");
     else{
        scanf("%d",p->queue[p->rear]);
        p->rear +=1;
        if(p->rear == m+1)
        p->rear = 1;
        p->queue[p->rear - 1]=x;
        p->s=1;
        }  
    OutQueue(p,6);
}


int main() {
    printf("请输入五组数据:\n");
    InitQueue(p);
    InQueue(p,6);
    return 0;
}

###### 运行结果及报错内容 
不能输入,直接运行结束


  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-10-17 21:47
    关注

    Queue_Type *p 指针没有分配空间啊
    建议改成 Queue_Type p;然后InitQueue(&p);这样子,后续参数为Queue_Type 类型的,都传递&p就好了
    或者在main函数开始时加上
    p = (Queue_Type
    )malloc(sizeof(Queue_Type));

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 10月25日
  • 已采纳回答 10月17日
  • 创建了问题 10月17日

悬赏问题

  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数
  • ¥15 ADS时域 连续相位观察方法
  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused