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
implementation of fast fourier transforms for non power of 2

Write the non-recursive algorithm to traverse a tree in preorder.    The Non- Recursive algorithm for preorder traversal is as follows: Initially  push NULL onto stack and

algorithm for multiplication of two sparse matrices using linked lists..

Ruby implements Range of T Abstract data type Ruby implements Range of T ADT in its Range class. Elements of carrier set are represented in Range instances by recording interna

merge sort process for an example array {38, 27, 43, 3, 9, 82, 10}. If we take a closer look at the diagram, we can see that the array is recursively divided in two halves till the

Type of Qualitative Method: Different  qualitative methods are suitable for different  types of study. Quite often we can  combine  qualitative and quantitative  methods. Many

A graph G might be defined as a finite set V of vertices & a set E of edges (pair of connected vertices). The notation utilized is as follows: Graph G = (V, E) Consider the g

Program: Creation of a Circular linked list ALGORITHM (Insertion of an element into a Circular Linked List) Step 1        Begin Step 2      if the list is empty or new

Red-Black trees have introduced a new property in the binary search tree that means an extra property of color (red, black). However, as these trees grow, in their operations such