Answered step by step
Verified Expert Solution
Link Copied!

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()
{
m_key =0;
m_data =0;
m_npl =0;
m_right = nullptr;
m_left = nullptr;
}
Node(int key, int data)
{
m_key = key;
m_data = data;
m_npl =0;
m_right = nullptr;
m_left = nullptr;
}
const Node &operator=(const Node &rhs)
{
if (this != &rhs)
{
m_key = rhs.m_key;
m_data = rhs.m_data;
m_npl = rhs.m_npl;
m_right = rhs.m_right;
m_left = rhs.m_left;
}
return *this;
}
friend class LHeap;
private:
int m_key;
int m_data;
int m_npl;
Node *m_right;
Node *m_left;
};
In LHeap class, there should be atleast these functions defined:
findMin()= O(1)
deleteMin()= O(log n)
insert()= O(log n)
merge()= O(log 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::merge(LHeap *h){
this>m_root = merge(this>m_root, h>m_root);
}
Private:
Node * LHeap::merge(Node *H1, Node *H2){
if (H1== NULL) return H2;
if (H2== NULL) return H1;
if (H1>m_key > H2>m_key)
return merge(H2,H1);
H1>m_right = merge(H1>m_right,H2);
updateNode(H1);
return H1;
}
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

Students also viewed these Databases questions

Question

=+b) Cut the runs to 8 by testing only in hot water.

Answered: 1 week ago