C PROGRAM TO SHOW PRE-ORDER, POST-ORDER & IN-ORDER TRAVERSALS OF A BINARY TREE

itstudentjunction


C PROGRAM TO SHOW PRE ORDER, POST ORDER & IN ORDER TRAVERSALS OF A BINARY TREE - DATA STRUCTURES PROGRAMS

WRITE A C PROGRAM TO SHOW PRE-ORDER, POST-ORDER & IN-ORDER TRAVERSALS OF A BINARY TREE


#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int data;
struct node *left,*right;
};
struct node *root;
void ins(struct node *n,int val,int opt)
{
struct node *t;
t=(struct node *)malloc(sizeof(struct node));
t->data=val;
t->right=t->left=NULL;
if (opt==1)
n->left=t;
else
n->right=t;
printf("\n %d is inserted",val);
if (opt==1)
{
printf("\tat the left\n");
getch();
}
else
{
printf("\tat the right\n");
getch();
}
}
void inser(struct node *t,int x)
{
if (t->data >x)
if (t->left==NULL)
ins(t,x,1);
else
inser(t->left,x);
else if (t->data < x)
if (t->right==NULL)
ins(t,x,2);
else
inser(t->right,x);
else
printf("\n Element is already present in the list\n");
}
void inorder(struct node *p)
{
if (p!=NULL)
{
inorder(p->left);
printf("\n %5d",p->data);
inorder (p->right);
}
}

void preorder(struct node *p)
{
if (p!=NULL)
{
printf("\n %5d",p->data);
preorder(p->left);
preorder (p->right);
}
}
void postorder(struct node *p)
{
if (p!=NULL)
{
preorder(p->left);
preorder (p->right);
printf("\n %5d",p->data);
}
}
void main()
{
int op,n;
root=(struct node *)malloc(sizeof(struct node));
root->data=30;
root->right=root->left=NULL;
clrscr();
do
{
printf("\n 1.Insertion");
printf("\n 2.Preorder");
printf("\n 3.Inorder");
printf("\n 4.Postorder");
printf("\n 5.Quit");
printf("\n Enter your choice\n");
scanf("%d",&op);
switch (op)
{
case 1: printf("\n Enter the element to insert\n");
scanf("%d",&n);
inser(root,n);
break;
case 2: printf("\n The preorder elements are\n");
preorder(root);
getch();
break;
case 3: printf("\n The inorder elements are\n");
inorder(root);
getch();
break;
case 4: printf("\n The postorder elements are\n");
postorder(root);
getch();
break;
default: exit(0);
}
}while(op<5);
getch();
}
 






Custom Search



write a c program MULTIPLICATION OF TWO MATRICES write a c program PRINT TRANSPOSE OF A MATRIX PRINT STRINGS LEXICOGRAPHIC ORDER CHECK IF string IS SUBSTRING OF OTHER STRING ALSO THE POSITION OF THE SUB STRING write a c program to CONCATENATE TWO STRINGS PRINT THE STUDENT INFORMATION ,RANK SECURED IN ASCENDING ORDER. MULTIPLY TWO SPARCE MATRICES TAKE PARAGRAPH AS INPUT AND OUTPUT NO, OF OCCURRENCES OF STRING IN PARAGRAPH CREATE ADD / INSERT, DISPLAY / SHOW, REMOVE / .DELETE ELEMENTS OF A LIST USING POINTERS REVERSE AN INPUT STRING CONVERT PREFIX EXPRESSION TO A POSTFIX expression USING POINTERS CREATE ADD / INSERT , DELETE / REMOVE, DISPLAY / SHOW ELEMENTS FROM SINGLE LINKED LIST CREATE ADD / insert REMOVE; DISPLAY ELEMENTS FROM DOUBLE LINKED LIST COUNT NUMBER OF NODES IN LINEAR LINKED LIST CREATE ADD / INSERT, DELETE / REMOVE; DISPLAY / SHOW ELEMENTS FROM CIRCULAR LINKED LIST / IMPLEMENT CIRCULAR LINKED LIST / write a C PROGRAM TO CONCATENATE TWO LINEAR LINKED LISTS ACCEPT 2 SINGLY LINKED LISTS PRINT A LIST THOSE ELEMENTS ARE COMMON IN BOTH LINKED LIST WRITE A C PROGRAM TO ACCEPT A SINGLY LINKED LIST OF INTEGERS & SORT THE LINKED LIST IN ASCENDING ORDER. IMPLEMENT CIRCULAR LINKED LIST IN C REVERSE LINKED LIST REPRESENT POLYNOMIAL USING LINKED LIST ADD TWO POLYNOMIALS USING LINKED LIST C PROGRAM TO IMPLEMENT STACK USING ARRAYS IMPLEMENT STACK USING LINKED LIST / IMPLEMENT STACK AS LINKED LIST MULTIPLE STACK IN A SINGLE ARRAY / IMPLEMENT MULTIPLE STACK C PROGRAM TO SHOW EXPRESSION TREE USING STACKS AND ITS INORDER, PREORDER , POST ORDER TRAVERSALS CONVERT INFIX NOTATION TO POSTFIX NOTATION USING STACKS IMPLEMENT QUEUE USING ARRAYS / CREATE , ADd / INSERT, DISPLAY / SHOW, REMOVE / DELETE ELEMENTS IN QUEUE WITH PONTERS CREATE ADD / INSERT, DISPLAY / SHOW, DELETE / REMOVE ELEMENTS FROM QUEUE WITH POINTERS IMPLEMENT QUEUE USING POINTERS IMPLEMENT CIRCULAR QUEUE USING ARRAYS IMPLEMENT DEQUEUE USING ARRAYS REVERSE ELEMENTS IN A QUEUE CREATE BINARY TREE / CREATION OF BINARY TREE ALSO INSERTION,DELETION PRE-ORDER,POST-ORDER ,IN-ORDER TRAVERSALS OF A BINARY COUNT NO, OF LEAVES OF BINARY TREE IMPLEMENTATION OF B-TREE (INSERTION,DELETION) WRITE A C IMPLEMENTATION OF MULTIWAY TREE IN C WRITE A C PROGRAM FOR IMPLEMENTATION OF AVL TREE / CREATE ADD / INSERT, DISPLAY / SHOW REMOVE / DELETE ELEMENTS OF AVL TREE WRITE A C PROGRAM FOR IMPLEMENTATION OF SPLAY TREE WRITE A C PROGRAM FOR IMPLEMENTATION OF RED-BLACK TREE write a c program show HASHING USING OPEN ADDRESSING IMPLEMENT HASHING USING OPEN ADDRESSING IMPLEMENT PRIORITY QUEUE USING HEAP DIJKSTRA'S ALGORITHM USING PRIORITY QUEUES IMPLEMENT KNAPSACK PROBLEM USING BACKTRACKING ADD ,DELETE NODES FROM ADJACENCY LIST DEPTH FIRST SEARCH MINIMAL SPANNING TREE USING KRUSKAL'S ALGORITHM MINIMAL SPANNING TREE USING PRIMS ALGORITHM SHOW BREADTH FIRST SEARCH SHOW LINEAR SEARCH WITH HELP OF POINTERS / IMPLEMENT LINEAR SEARCH USING POINTERS SHOW BINARY SEARCH WITH HELP OF POINTERS / IMPLEMENT BINARY SEARCH USING POINTERS SEARCH FOR POSITIONOF ELEMENT USING LINEAR SEARCH / IMPLEMENT LINEAR SEARCH USING ARRAYS SEARCH FOR POSITION OF ELEMENT USING INARY SEARCH / IMPLEMENT BINARY SEARCH USING ARRAYS IMPLEMENT BUBBLE SORT PROGRAM USING ARRAYS IMPLEMENT MERGE SORT USING ARRAYS IMPLEMENT SELECTION SORT PROGRAM USING ARRAYS INSERTION SORT PROGRAM USING ARRAYS IMPLEMENT TOPOLOGICAL SORT USING ARRAYS WRITE A C PROGRAM TO IMPLEMENT HEAP SORT USING ARRAYS, SORT ELEMENTS USING HEAP SORT write a c program to implement HEAP SORT USING POINTERS write a C PROGRAM TO SHOW BUBBLE SORT PROGRAM / IMPLEMENT BUBBLE SORT PROGRAM USING arrays Ignou Mca assignments Ignou bca assignments C ProgramsC Lab records Data structures Programs in c Data structures Programs in c++ Computer Graphics Programs Computer Graphics ProgramsComputer Graphics lab programs Unix commandsunix lab solutions> Linux commands Linux lab solutions HTML programming HTML lab programs C++ programs, C++ Lab programs Data structures Algorithms Web technologies programmingWeb technologies Lab programs Java Programs Java lab programs UML Diagrams uml LabAssembly Language Programsignou mca bcaStudy Abroad Mca Syllabus BCA syllabusBtech SyllabusMtech Syllabus engineering collegesmca colleges Softwares IT Jobs Certification exams Free Softwares downloads