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
Which sorting algorithms does not have a worst case running time of  O (n 2 ) ? Merge sort

Write the algorithm for compound interest

Circular Queues:- A more efficient queue representation is get by regarding the array Q(1:n) as circular. It becomes more convenient to declare the array as Q(O: n-1), when  re

Board coloring , C/C++ Programming

Write an algorithm for binary search. What are its limitations? .

With the help of a program and a numerical example explain the Depth First Traversal of a tree.

Explain the Scan-Line Algorithm This image-space method for removing hidden surfaces is an extension of the scan-line algorithm for filling polygon interiors. Instead of fillin

This is a k-ary position tree wherein all levels are filled from left to right. There are a number of specialized trees. They are binary trees, AVL-trees, binary search trees, 2

Q. Reverse the order of the elements on a stack S    (i) by using two additional stacks (ii) by using one additional queue. Ans :      L e t S be the stac

Here,  m represents the unordered array of elements n  represents number of elements in the array and el  represents the value to be searched in the list Sep 1: [Initialize]