Question: No STL allowed answer in c + + 3 . ( 1 0 points ) Implement the ternary heap structure ( each node can have
No STL allowed answer in c points Implement the ternary heap structure each node can have up to children The heap must support the following methods:
Insert
GetMin
Heapify i swap the elements from i such that the array becomes a heap
DeleteMin
BuildHeap rearrange the array to make it become a heap
class BSTree
public:
Node root;
BSTreeNode r
root r;
void print
rootprint;
cout endl;
void rotateRightNode Gr Node Par Node Ch
if Gr NULL
grandparent Gr of child Ch becomes Chs parent Par
Parleft Chright;
if Chright NULL
Chrightparent Par;
node Ch acquires Par as its right child
Chright Par;
Parparent Ch;
Grright Ch; What if Par was the left child of Gr
Chparent Gr;
What if Gr NULL
void rotateLeftNode Gr Node Par Node Ch
if Gr NULL
grandparent Gr of child Ch becomes Chs parent Par
Parright Chleft;
if Chleft NULL
Chleftparent Par;
node Ch acquires Par as its left child
Chleft Par;
Parparent Ch;
Grleft Ch; What if Par was the right child of Gr
Chparent Gr;
What if Gr NULL
Node searchstring data
works for the toy example, needs to be replaced by binary search
return rootrightleftleft;
void splaystring data
Node Ch searchdata;
Node Par Chparent;
Node Gr Parparent;
if Gr NULL
rotateRightGr Par, Ch; or rotateLeft
else
Zig Zig
if Grleft Par && Parleft Ch
rotateRightGrparent, Gr Par;
print;
Ch was pushed up hence having new Par and Gr
Par Chparent;
Gr Parparent;
rotateRightGr Par, Ch;
print;
Zig Zag
else if Grleft Par && Parright Ch
rotateLeftGrPar,Ch;
print;
Ch was pushed up hence having new Par and Gr
Par Chparent;
Gr Parparent;
rotateRightGrPar,Ch;
Zag Zig
Zag Zag
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
