Question: * * * No STLs are allowed * * * answer in c + + also use the provided material Implement the splay ( )
No STLs are allowed answer in c also use the provided material
Implement the splay operation as discussed in class. Some incomplete codes are given the attachment as hints. Two testing examples are given below.
Example :
Original tree:
After SlayT:
No STLs are allowed
Example :
After SlayR:
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
