
#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;elsecout<<"链队列不为空"<<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;}
其实错误提示信息已经写得很清楚了,无法将Qnode * 转化成为 node *
你的 p 定义为 Qnode * 而你的Qnode结构体里面 next 的定义为 struct node* 所以无法转化
你将 Qnode结构体里面 struct node* 改成 struct Qnode* 试试。