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
State about the pre- and post conditions Programmers can easily document other pre- and post conditions and class invariants, though, and insert code to check most value preco

1) preorder, postorder and inorder 2) The main feature of a Binary Search Tree is that all of the elements whose values is less than the root reside into the nodes of left subtr

what is frequency count with examble? examble?

how can i delete from deque while deletion is restricted from one end

In the last subsection, we have implemented a stack by using an array. While a stack is implemented by using arrays, it suffers from the basic restriction of an array - i.e., its s

what is circular doubly link list?write down the algorithm for insertion of elements in circular doubly link list

Multidimensional array: Multidimensional arrays can be defined as "arrays of arrays". For example, a bidimensional array can be imagined as a bidimensional table made of elements,

Objective The goal of this project is to extend and implement an algorithm presented in the course and to apply notions introduced by the course to this program/algorithm. The ass

A full binary tree with 2n+1 nodes have n non-leaf nodes