Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include using namespace std; struct Node { int data; Node * left; Node * right; } ; const int MAXSIZE = 1 0 ; Node
#include
using namespace std;
struct Node
int data;
Node left;
Node right;
;
const int MAXSIZE ;
Node queueMAXSIZE;
int front rear ;
void resetQueue
rear ;
front ;
bool queueIsEmpty
if front
return true;
else
return false;
bool queueIsFull
if rear MAXSIZE front
return true;
else
return false;
Node peek return queuefront;
void printQueue
if queueIsEmpty
int i ;
for i front; i rear;
cout queueidata ;
i i MAXSIZE;
cout queueidata ;
cout endl;
void enqueueNode data
if queueIsFull
if front
front ;
rear ;
else
rear rear MAXSIZE;
queuerear data;
else
cout "Queue is full" endl;
Node dequeue
Node data queuefront;
if front rear
rear ;
front ;
else
front front MAXSIZE;
return data;
void preorderNode n
if n NULL
cout ndata ;
preordernleft;
preordernright;
void inorderNode n
if n NULL
inordernleft;
cout ndata ;
inordernright;
void postorderNode n
if n NULL
postordernleft;
postordernright;
cout ndata ;
void levelorderNode n
if n NULL
enqueuen;
while queueIsEmpty
Node temp dequeue;
cout tempdata ;
if templeft NULL
enqueuetempleft;
if tempright NULL
enqueuetempright;
Node insertNode n int x
Node newNode new Node;
newNodedata x;
newNodeleft NULL;
newNoderight NULL;
if n NULL
n newNode;
else
enqueuen;
while queueIsEmpty
Node temp dequeue;
if templeft NULL
templeft newNode;
break;
else
enqueuetempleft;
if tempright NULL
tempright newNode;
break;
else
enqueuetempright;
return n;
Node deleteTreeDeepestRightMostNodeNode n Node targetNode
enqueuen;
while queueIsEmpty
Node temp dequeue;
if temp targetNode when targed node is the root node
delete temp;
return NULL;
if templeft NULL && templeft targetNode
enqueuetempleft;
else
if templeft NULL
delete templeft;
templeft NULL;
return n;
if tempright NULL && tempright targetNode
enqueuetempright;
else
if tempright NULL
delete tempright;
tempright NULL;
return n;
return n;
Node deleteTreeNodeNode n int x
enqueuen;
Node tobedeleted;
Node deepestRightMostNode;
while queueIsEmpty
Node temp dequeue;
deepestRightMostNode temp;
if tempdata x
tobedeleted temp;
if templeft NULL
enqueuetempleft;
if tempright NULL
enqueuetempright;
resetQueue;
tobedeleteddata deepestRightMostNodedata;
n deleteTreeDeepestRightMostNoden deepestRightMostNode;
return n;
int main
Node root NULL;
root insertroot;
root insertroot;
resetQueue;
root insertroot;
resetQueue;
root insertroot;
resetQueue;
root insertroot;
resetQueue;
preorderroot;
cout endl;
inorderroot;
cout endl;
postorderroot;
cout endl;
levelorderroot;
resetQueue;
cout endl;
root deleteTreeNoderoot;
resetQueue;
levelorderroot;
resetQueue;
root deleteTreeNoderoot;
resetQueue;
cout endl;
levelorderroot;
resetQueue;
cout endl;
return ;
answer with the following code provided
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