Procedure to delete all terminal nodes of the tree, Data Structure & Algorithms

Assignment Help:

Q. Let a binary tree 'T' be in memory. Write a procedure to delete all terminal nodes of the tree.      

Ans.

function to Delete Terminal Nodes from Binary Tree

void deleteleaves(struct node* root,struct node* prev)

{

 

if(root)

{

if(root->left==NULL&&root->right==NULL)

{

if(prev->item>=root->item)

prev->left=NULL;

else

prev->right=NULL;

printf("\n\n  %d Is Being Deleted ...",root->item);

free(root);

return;

}

deleteleaves(root->left,root);

deleteleaves(root->right,root);

}

}

the call to this function will deleteleaves (root, root).


Related Discussions:- Procedure to delete all terminal nodes of the tree

Stack, Explain the array and linked list implementation of stack

Explain the array and linked list implementation of stack

Randomized algorithm, need an expert to help me with the assignment

need an expert to help me with the assignment

Algorithm, write an algorithm for the gpa of six students

write an algorithm for the gpa of six students

Define spanning tree, Define Spanning Tree A Spanning Tree of a connect...

Define Spanning Tree A Spanning Tree of a connected graph is its linked acyclic sub graph (i.e., a tree) that having all the vertices of the graph.

ALGORITHM AND TRACING, WRITE AN ALGORITHM TO CONVERT PARENTHIZED INFIX TO P...

WRITE AN ALGORITHM TO CONVERT PARENTHIZED INFIX TO POSTFIX FORM ALSO TRACE ALG ON ((A+B)*C-(D-E)$F+G)

Depth first search and breadth first search, Q. Illustrate the result of ru...

Q. Illustrate the result of running BFS and DFS on the directed graph given below using vertex 3 as source.  Show the status of the data structure used at each and every stage.

Consistent heuristic function - graph search, Consistent Heuristic Function...

Consistent Heuristic Function - Graph Search Recall the notions of consistency and admissibility for an A* search heuristic. a. Consider a graph with four nodes S, A, B, C,

Data manipulation, perform the following length operation LENGTH("welcome t...

perform the following length operation LENGTH("welcome to ICA")=

Write an algorithm for binary search., Write an algorithm for binary search...

Write an algorithm for binary search. Algorithm for Binary Search 1.  if (low> high) 2.  return (-1) 3.  Mid = (low + high)/2 4.  if ( X = = a[mid]) 5.  return (mid); 6.

Implementation of circular queues, One of the main problems with the linear...

One of the main problems with the linear queue is the lack of appropriate utilization of space. Assume that the queue can store 100 elements & the complete queue is full. Thus, it

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd