Question: In c + + , create a leftist heap data structure class called LHeap which uses Node class that looks like this: class Node {
In c create a leftist heap data structure class called LHeap which uses Node class that looks like this:
class Node
public:
Node
mkey ;
mdata ;
mnpl ;
mright nullptr;
mleft nullptr;
Nodeint key, int data
mkey key;
mdata data;
mnpl ;
mright nullptr;
mleft nullptr;
const Node &operatorconst Node &rhs
if this &rhs
mkey rhsmkey;
mdata rhsmdata;
mnpl rhsmnpl;
mright rhsmright;
mleft rhsmleft;
return this;
friend class LHeap;
private:
int mkey;
int mdata;
int mnpl;
Node mright;
Node mleft;
;
In LHeap class, there should be atleast these functions defined:
findMin O
deleteMin Olog n
insert Olog n
merge Olog n
print prints the nodes of the leftist heap
Any helper function should be declared as private and any member variable should be private and have m declared before the name. Here is an example of how public and private function for merge works:
Public:
void LHeap::mergeLHeap h
thismroot mergethismroot, hmroot;
Private:
Node LHeap::mergeNode H Node H
if H NULL return H;
if H NULL return H;
if Hmkey Hmkey
return mergeHH;
Hmright mergeHmright,H;
updateNodeH;
return H;
Implement all functions of LHeap class in the lheap.cpp and keep the classes itself in lheap.h
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
