C-program to make a copy of a tree

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


Solution:

#include<stdio.h>
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;
}
}




Click Here For More Questions

7 comments:

  1. I like your suggestions they are really helpful. Thank you so much for sharing this post.

    Java and J2EE Training in Chennai - AmitySoft

    ReplyDelete
  2. Thank you for this post.icecreamhaven.in Vanilla is the most iconic and versatile ice cream flavor. With its creamy texture and subtle sweetness, it pairs perfectly with almost any topping or dessert.

    ReplyDelete
  3. Thank you for sharing such a clear and insightful piece. I truly found your ideas valuable and engaging. I really appreciate how you connected different industries and perspectives, it gave me a fresh way to think about it.
    Root Canal Treatment In Madinaguda

    ReplyDelete
  4. Nice Article!

    Thanks for sharing with us 🙂

    Best Dental Clinic in Madinaguda

    ReplyDelete