Sunday, August 19, 2012

Delete a Tree


#include<stdio.h>
struct binarysearchtree
{
      int data;
      struct binarysearchtree* left;
      struct binarysearchtree* right;
};
typedef struct binarysearchtree* tree;

void tree_free(tree T)
{
  if (T==NULL)
     return;
  else
  {
      tree_free(T->left);
      tree_free(T->right);
      free(T);
  }
}

2 comments:

  1. This is a brilliant collection of most of the algorithms that you can find recurring from interview to interview. Amazing work! :)

    - NK

    ReplyDelete
  2. i believe it should be:
    void tree_free(tree *T)

    ReplyDelete