Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started