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

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).

Posted Date: 7/13/2012 1:14:26 AM | Location : United States







Related Discussions:- Procedure to delete all terminal nodes of the tree, Assignment Help, Ask Question on Procedure to delete all terminal nodes of the tree, Get Answer, Expert's Help, Procedure to delete all terminal nodes of the tree Discussions

Write discussion on Procedure to delete all terminal nodes of the tree
Your posts are moderated
Related Questions
#question.show that the following inequality is correct or incorrect. n!=O(n^n)

Write down any four applications of queues.            Application of Queue (i)  Queue is used in time sharing system in which programs with the similar priority form a queu

algorithm for insertion in a queue using pointers

The process of accessing data stored in a serial access memory is same to manipulating data on a By using stack  method.

Which of the sorting algorithm is stable   Heap sorting is stable.

Explain All-pair shortest-paths problem Given a weighted linked graph (undirected or directed), the all pairs shortest paths problem asks to find the distances (the lengths of

Q. What do you understand by the term Binary Tree? What is the maximum number of nodes which are possible in a Binary Tree of depth d. Explain the terms given below with respect to

Binary Space Partition A binary space-partitioning (BSP) tree is an efficient method for determining object visibility by painting surfaces onto the screen from back to front,

The number of interchanges needed to sort 5, 1, 6, 2 4 in ascending order using Bubble Sort is 5

Records are mapped onto a computer store by simply juxtaposing their elements. The address of a component (field) r relative to the origin address of the record r is named the fiel