Tree
Tree
Tree
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct tnode {
int data;
struct tnode * leftc;
struct tnode * rightc;
};
int main() {
struct tnode * root=NULL;
char ch[5];
int num;
do {
printf("Enter the element to be inserted in the tree\n");
scanf("%d",&num);
insert(&root, num);
printf("Do you want to insert another element?\n");
scanf("%s",ch);
}while(strcmp(ch,"yes")==0);
printf("Inorder Traversal : The elements in the tree are");
inorder(root);
printf("\n");
printf("Preorder Traversal : The elements in the tree are");
preorder(root);
printf("\n");
printf("Postorder Traversal : The elements in the tree are");
postorder(root);
printf("\n");
return 0;
}
}
else {
if(num <(*s)->data)
insert(&((*s)->leftc),num);
else
insert(&((*s)->rightc),num);
}
-------------------- 2nd
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct tnode
{
int data;
struct tnode * leftc;
struct tnode * rightc;
};
int main() {
struct tnode * root=NULL;
char ch[5];
int num,ele;
do {
printf("Enter the element to be inserted in the tree\n");
scanf("%d",&num);
insert(&root, num);
printf("Do you want to insert another element?\n");
scanf("%s",ch);
}while(strcmp(ch,"yes")==0);
printf("Inorder Traversal : The elements in the tree are");
inorder(root);
printf("\n");
printf("Enter the element to be searched\n");
scanf("%d",&ele);
if(search(root,ele))
printf("%d found\n",ele);
else
printf("%d not found\n",ele);
return 0;
}
return f;
else
return 0;
}
}
---------4
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct tnode
{
int data;
struct tnode * leftc;
struct tnode * rightc;
};
int main() {
struct tnode * root=NULL;
char ch[5];
int num;
do {
printf("Enter the element to be inserted in the tree\n");
scanf("%d",&num);
insert(&root, num);
printf("Do you want to insert another element?\n");
scanf("%s",ch);
}while(strcmp(ch,"yes")==0);
int main() {
struct tnode * root=NULL;
char ch[5];
int num;
do {
printf("Enter the element to be inserted in the tree\n");
scanf("%d ",&num);
insert(&root, num);
printf("Do you want to insert another element?\n");
scanf("%s",ch);
}while(strcmp(ch,"yes")==0);
int main() {
struct tnode * root=NULL;
char ch[5];
int num;
do {
printf("Enter the element to be inserted in the tree\n");
scanf("%d",&num);
insert(&root, num);
printf("Do you want to insert another element?\n");
scanf("%s",ch);
} while(strcmp(ch,"yes")==0);