柚子pomelo. 2022-10-10 13:23 采纳率: 100%
浏览 1064
已结题

这个要怎么改QAQ E3364 运算符 -> 或 ->* 应用于 "int" 而不是指针类型

问题遇到的现象和发生背景

就下面这个函数报错,要怎么改QAQ

void PrintQueue(SqQueue& Q)
{
    QElemType* p;
    if (Q.front == Q.rear)
    {
        printf("队空!\n");
    }
    p = Q.front->next;
    while (p)
    {
        printf("队列中元素为:\n");
        printf("%d",p->data);
        p=p->next;
    }
    printf("\n");
}

用代码块功能插入代码,请勿粘贴截图
#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int QElemType;
#define MAXQSIZE  100  //最大队列长度

typedef struct {
    QElemType data;
    QElemType* base;  // 动态分配存储空间
    int  front;     // 头指针,若队列不空,
                         //  指向队列头元素
    int  rear;     // 尾指针,若队列不空,指向
    //队列尾元素 的下一个位置
} SqQueue;
Status InitQueue(SqQueue& Q) {
    // 构造一个空队列Q
    Q.base = (QElemType*)malloc(MAXQSIZE * sizeof(QElemType));
    if (!Q.base) exit(OVERFLOW);
    // 存储分配失败
    Q.front = Q.rear = 0;
    return OK;
}
Status EnQueue(SqQueue& Q, QElemType e) {
    // 插入元素e为Q的新的队尾元素
    if ((Q.rear + 1) % MAXQSIZE == Q.front)
        return ERROR; //队列满
    Q.base[Q.rear] = e;
    Q.rear = (Q.rear + 1) % MAXQSIZE;
    return OK;
}
Status DeQueue(SqQueue& Q, QElemType& e) {
    // 若队列不空,则删除Q的队头元素,
    // 用e返回其值,并返回OK;  否则返回ERROR
    if (Q.front == Q.rear)  return ERROR;
    e = Q.base[Q.front];
    Q.front = (Q.front + 1) % MAXQSIZE;
    return OK;
}
int QueueLength(SqQueue Q)
{
    return (Q.rear - Q.front + MAXQSIZE) % MAXQSIZE;
}

void PrintQueue(SqQueue& Q)
{
    QElemType* p;
    if (Q.front == Q.rear)
    {
        printf("队空!\n");
    }
    p = Q.front->next;
    while (p)
    {
        printf("队列中元素为:\n");
        printf("%d",p->data);
        p=p->next;
    }
    printf("\n");
}

int main()
{
    SqQueue Q;
    int a, b, c, d;
    printf("请输入要入队的数字:\n");
    scanf("%d%d%d%d", &a, &b, &c, &d);
    EnQueue(Q, a);
    EnQueue(Q, b);
    EnQueue(Q, c);
    EnQueue(Q, d);
    PrintQueue(Q);
    printf("队列长度:\n");
    QueueLength(Q);
    int f;
    printf("请输入要入队的数字:\n");
    scanf("%d", &f);
    EnQueue(Q, f);
    printf("入队后:\n");
    PrintQueue(Q);
    printf("出队:\n");
    DeQueue(Q, a);
    PrintQueue(Q);
    return 0;
}

运行结果及报错内容

严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E3364 运算符 -> 或 ->* 应用于 "int" 而不是指针类型 队列 57
错误(活动) E0131 表达式必须包含指向类的指针类型,但它具有类型 "QElemType *" 61
错误(活动) E0131 表达式必须包含指向类的指针类型,但它具有类型 "QElemType *" 62
错误 C2227 “->next”的左边必须指向类/结构/联合/泛型类型 57

展开全部

  • 写回答

1条回答 默认 最新

  • liwq_jn 2022-10-11 01:33
    关注

    typedef int QElemType; 这是一个整形啊

    void PrintQueue(SqQueue& Q)
    {
    QElemType* p; //这是一个整形啊,是不是定义错了
    if (Q.front == Q.rear)
    {
    printf("队空!\n");
    }
    p = Q.front->next; //front也是整形,怎么指向next?next怎么来的?
    while (p)
    {
    printf("队列中元素为:\n");
    printf("%d",p->data); //整形怎么指针
    p=p->next; //这个怎么有next
    }
    printf("\n");
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    柚子pomelo. 2022-10-11 12:01

    谢谢Thanks♪(・ω・)ノ

    回复
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 10月18日
  • 已采纳回答 10月11日
  • 修改了问题 10月10日
  • 创建了问题 10月10日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部