Interview Questions For All

Interview Questions For All Who Are Waiting For Jobs

Thursday, July 24, 2008

C-program to make a copy of a tree

7.Write a C program to create
a copy of a tree

Solution:


#include
struct binarysearchtree{
int data;
struct binarysearchtree* left;
struct binarysearchtree* right;
};
typedef struct binarysearchtree* tree;

tree copy(tree T)
{
if(T== NULL)
return NULL;
else
{
tree *newtree=(tree*)malloc(sizeof(tree));
newtree->data=tree->data;
newtree->left=copy(T->left);
newtree->right=copy(T->right);
return newtree;
}
}


piot at 7:58 AM

No comments:

Post a Comment

‹
›
Home
View web version
Powered by Blogger.