m0_67745779 2022-03-31 14:54 采纳率: 70%
浏览 29
已结题

请问这个是哪里错啦,我的结点定义的不对吗

img


#include"iostream"
using namespace std;
typedef int ElemType;
typedef struct Qnode
{
ElemType data;
struct node *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)
{
cout<<"初始化失败"<<endl;
}
else
{
cout<<"初始化成功"<<endl;
Q.front->next=NULL;
}
}
void EmptyQueue(LinkQueue Q)
{
if(Q.rear==Q.front)
cout<<"链队列为空"<<endl;
else
cout<<"链队列不为空"<<endl;
}
void EnQueue(LinkQueue &Q)
{
int n;
cout<<"请输入您想入队几位数"<<endl;
for(int i=0;i<n;i++)
{
Qnode *p;
p=new Qnode;
cout<<"请输入您想要入队的元素"<<endl;
cin>>p->data;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
}
}
int main()
{
LinkQueue Q;
InitQueue(Q);
EmptyQueue(Q);
EnQueue(Q);
return 0;
}

  • 写回答

1条回答 默认 最新

  • zzzfly 2022-03-31 15:23
    关注

    其实错误提示信息已经写得很清楚了,无法将Qnode * 转化成为 node *
    你的 p 定义为 Qnode * 而你的Qnode结构体里面 next 的定义为 struct node* 所以无法转化
    你将 Qnode结构体里面 struct node* 改成 struct Qnode* 试试。

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

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 修改了问题 3月31日
  • 创建了问题 3月31日

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常