Program for demonstration of Tree Operations - INSERTION, INORDER .

# include
# include
# include

struct node
{
struct node *left;
int data;
struct node *right;
};

void main()
{
void insert(struct node **,int);
void inorder(struct node *);
void postorder(struct node *);
void preorder(struct node *);
struct node *ptr;
int will,i,num;
ptr = NULL;
ptr->data=NULL;
clrscr();

printf("Enter the number of terms you want to add to the tree.");
scanf("%d",&will);

/* Getting Input */
for(i=0;i {
printf("Enter the item");
scanf("%d",&num);
insert(&ptr,num);
}

getch();
printf("INORDER TRAVERSAL");
inorder(ptr);
getch();
printf("PREORDER TRAVERSAL");
preorder(ptr);
getch();
printf("POSTORDER TRAVERSAL");
postorder(ptr);
getch();
}



void insert(struct node **p,int num)
{


if((*p)==NULL)
{ printf("Leaf node created.");
(*p)=malloc(sizeof(struct node));
(*p)->left = NULL;
(*p)->right = NULL;
(*p)->data = num;
return;
}
else
{ if(num==(*p)->data)
{
printf("REPEATED ENTRY ERROR
VALUE REJECTED");
return;
}
if(num<(*p)->data)
{
printf("
Directed to left link.");
insert(&((*p)->left),num);
}
else
{
printf("Directed to right link.");
insert(&((*p)->right),num);
}
}
return;
}


void inorder(struct node *p)
{
if(p!=NULL)
{
inorder(p->left);
printf("Data :%d",p->data);
inorder(p->right);
}
else
return;
}


void preorder(struct node *p)
{
if(p!=NULL)
{
printf("Data :%d",p->data);
preorder(p->left);
preorder(p->right);
}
else
return;
}


void postorder(struct node *p)
{
if(p!=NULL)
{
postorder(p->left);
postorder(p->right);
printf("
Data :%d",p->data);
}
else
return;
}

0 comments:

Post a Comment

Latest New Programs Updates...

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******I.G.C.T. Computers*******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"INFO COMPUTERS\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT Computers | \n\n");
printf ("\t\t\t | Info Computers | \n\n");
printf ("\t\t\t | 108,Sambhaji Nagar | \n\n");
printf ("\t\t\t | Lokhande Nagar. NGP-22| \n\n");
printf ("\t\t\t | Ph : 9373144662 | \n\n");
printf ("\t\t\t --------------------------- ");
printf ("\t\t\t www.igct.co.cc ");
getch ();

}

For More Tutors Visite : www.igct.tk

Program for adding two number using different data types


#include
#include

void main ()
{
int ia,ib,ic;
unsigned int ua,ub,uc;
long la,lb,lc;
long unsigned lua,lub,luc;
float fa,fb,fc;
double lfa,lfb,lfc;
long double La,Lb,Lc;
clrscr ();

printf ("\n\t\t Program for adding two number using different data types");



printf ("\n\n\n ***Enter two number of Integer type***");
printf ("\n\n Enter first number->");
scanf ("%d",&ia);
printf ("\n\n Enter second number->");
scanf ("%d",&ib);
ic=ia+ib;
printf ("\n\n\t Addition = %d",ic);



printf ("\n\n\n ***Enter two number of Unsigned type***");
printf ("\n\n Enter first number->");
scanf ("%u",&ua);
printf ("\n\n Enter second number->");
scanf ("%u",&ub);
uc=ua+ub;
printf ("\n\n\t Addition = %u",uc);



printf ("\n\n\n ***Enter two number of long type***");
printf ("\n\n Enter first number->");
scanf ("%ld",&la);
printf ("\n\n Enter second number->");
scanf ("%ld",&lb);
lc=la+lb;
printf ("\n\n\t Addition = %ld",lc);



printf ("\n\n\n ***Enter two number of long Unsined type***");
printf ("\n\n Enter first number->");
scanf ("%lu",&lua);
printf ("\n\n Enter second number->");
scanf ("%lu",&lub);
luc=lua+lub;
printf ("\n\n\t Addition = %lu",luc);



printf ("\n\n\n ***Enter two number of Float type***");
printf ("\n\n Enter first number->");
scanf ("%f",&fa);
printf ("\n\n Enter second number->");
scanf ("%f",&fb);
fc=fa+fb;
printf ("\n\n\t Addition = %f",fc);



printf ("\n\n\n ***Enter two number of double type***");
printf ("\n\n Enter first number->");
scanf ("%lf",&lfa);
printf ("\n\n Enter second number->");
scanf ("%lf",&lfb);
lfc=lfa+lfb;
printf ("\n\n\t Addition = %lf",lfc);



printf ("\n\n\n ***Enter two number of long double type***");
printf ("\n\n Enter first number->");
scanf ("%Lf",&La);
printf ("\n\n Enter second number->");
scanf ("%Lf",&Lb);
Lc=La+Lb;
printf ("\n\n\t Addition = %Lf",Lc);




getch ();

}
Google