[渣渣求助大神]就要交课程设计作业了

[复制链接]
查看11 | 回复3 | 2021-1-27 05:21:01 | 显示全部楼层 |阅读模式
要求是要做一个优先队列要实现初始化、查找、插入、删除算法需要用堆排序的(复杂度logn)老师也给了个PDF文件让自学里面是“第九章优先队列balabala”百度文库也有
然后我就各种复制代码书上的PDF里的网上的(所以有很多没用的也在里面不好意思)
虽然不知道最后能不能实现但是现在运行还是有六个error实在是怎么都解决不了后附图无处问人跪求大神解救

#include
#include
#include
#include
#include
#defineOVERFLOW0
#defineOK1
#defineERROR0
#defineture1
usingnamespacestd;
typedefintStatus;
typedefintQElemType;
typedefintT;
typedefstructQNode{
QElemTypedata;
structQNode*next;
}QNode,*QueuePtr;
typedefstruct{
QueuePtrfront;
QueuePtrrear;
}LinkQueue;
template
classNode{
private:
Tdata;
Node*next;
};
template
classQueue{
public:
Queue(){front=rear=0;}
~Queue();
boolEmpty()const{return((front)?false:ture);}
boolFull()const;
TFirst()const;
TLast()const;
Queue&EnQueue(constT&x);
Queue&DeQueue(T&x);
//private:
Node*front;
Node*rear;
};
StatusInitQueue(LinkQueue&Q){
Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q.front)exit(OVERFLOW);
Q.front->next=NULL;
returnOK;
}
template
Queue&Queue::EnQueue(constT&x)
{if(Full())exit(0);
Node*p=newNode;
p->data=x;
p->next=0;
if(front)rear->next=p;
elsefront=p;
rear=p;
return*this;
}
template
Queue&Queue::DeQueue(T&x)
{if(Empty())exit(0);
x=front->data;
Node*p=front;
front=front->next;
deletep;
return*this;
}

template
classHBLTNode{
public:
HBLTNode(constT&e,constintsh)
{data=e;
s=sh;
LeftChild=RightChild=0;}
ints;
//private:
Tdata;
HBLTNode*LeftChild,*RightChild,*LR;
};
template
classMaxHBLT{
public:
MaxHBLT(){root=0;}
~MaxHBLT(){Free(root);}
TMax(){if(!root)exit(0);
returnroot->data;}
MaxHBLT&Insert(constT&x);
MaxHBLT&DeleteMax(T&x);
MaxHBLT&Meld(MaxHBLT&x){
Meld(root,x.root);
x.root=0;
return*this;}
voidInitialize(Ta[],intn);
//private:
voidFree(HBLTNode*t);
voidMeld(HBLTNode*&x,HBLTNode*y);
HBLTNode*root;
};
template
voidMaxHBLT::Meld(HBLTNode*&x,HBLTNode*y)
{
if(!y)return;
if(!x)
{x=y;
return;}
if(x->datadata)
swap(x,y);
Meld(x->RightChild,y);
if(!x->LeftChild){
x->LeftChild=x->RightChild;
x->RightChild=0;
x->s=1;}
else{
if(x->LeftChild->sRightChild->s)
swap(x->LeftChild,x->RightChild);
x->s=x->RightChild->s+1;}
}
template
MaxHBLT&MaxHBLT::Insert(constT&x)
{
HBLTNode*q=newHBLTNode(x,1);
Meld(root,q);
return*this;
}

template
MaxHBLT&MaxHBLT::DeleteMax(T&x)
{
if(!root)exit(0);
x=root->data;
HBLTNode*L=root->LeftChild;
HBLTNode*R=root->RightChild;
deleteroot;
root=L;
Meld(root,R);
return*this;
}
template
voidMaxHBLT::Initialize(Ta[],intn)
{
Queue>Q(n);//153
Free(root);
for(inti=1;i*q=newHBLTNode(a,1);
Q.EnQueue(q);//157
}
HBLTNode*b,*c;
for(inti=1;iH;
intn,choice,i,x;
cout>n;
inta[n];
cout>a;
}
H.Initialize(&a[n],n);
cout>choice;
while(choice)
{
switch(choice)
{case1:
coutdata>x;
H.Insert(x);
break;
case3:
x=H.DeleteMax(T&x);//196
cout -->
回复

使用道具 举报

千问 | 2021-1-27 05:21:01 | 显示全部楼层



回复

使用道具 举报

千问 | 2021-1-27 05:21:01 | 显示全部楼层



回复

使用道具 举报

千问 | 2021-1-27 05:21:01 | 显示全部楼层
https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/5.gif
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行