You are on page 1of 108

Hemwati Nandan Bahuguna Garhwal

University

Session 2018-2022
Practical File-Data Structure

Submitted To- Submitted By-


Mrs.Shailratna Bhatt Archana Bharti
B.Tech. (C.S.E. 3rdSem)

Department of Computer Science & Engineering


School of Engineering & Technology
INDEX
1) Write a program to implement following operations in array
a. Searching
b. Insertion
c. Deletion

2) Write a program to implement following operations in singly linked list


a. Searching
b. Insertion
c. Deletion

3) Write a program to implement following operations in a doubly linked list


a. Searching
b. Insertion
c. Deletion

4) Write a program to implement following operations in a circular linked list


a. Searching
b. Insertion
c. Deletion

5) Write a program to implement following operations in Stacks using Array and Linked
list:
a. Push
b. Pop

6) Write a program to implement following operations in Queue using Array and Linked
list:
a. Push
b. Pop

7) Write a program to implement following operations in DeQue using Array and Linked
list:
a. Push from front end
b. Pop from front end
c. Push from rear end
d. Pop from rear end
8) Write a program to implement following operations in Circular Queue using Array
and Linked list:
a. Push
b. Pop

9) Program to create binary tree and display using in-order traversal


Program to perform operations on Array
Search

#include<stdio.h>

int main()
{
int a[50],size,i,data;

printf("Enter the size of array.");


scanf("%d",&size);

printf("Enter the elements of array.\n");


for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
printf("Elements in array are:\n");

for(i=0;i<size;i++)
{
printf("%d\t",a[i]);
}

printf("\nEnter the data to be searched.\n");


scanf("%d",&data);

for(i=0;i<size;i++)
{
if(a[i]==data)
{
printf("Elements found at position-%d",i+1);
break;
}
}
if(i==size)
{
printf("Elements not found.");
}
}
OUTPUT:
Insert
#include<stdio.h>
int main()
{
int a[50],size,i,position,value;
printf("Enter the size of array.");
scanf("%d",&size);
printf("Enter the elements of array.\n");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
printf("\nElements in array are:\n");
for(i=0;i<size;i++)
{
printf("%d\t",a[i]);
}
printf("\nEnter the location where you wish to insert an element\n");
scanf("%d", &position);
if(position<=size)
{
printf("Enter the value to insert\n");
scanf("%d", &value);
for(i=size-1;i>=position-1;i--)
{
a[i+1]=a[i];
}
a[position-1]=value;
printf("Resultant array is\n");
for (i=0;i<=size;i++)
{
printf("%d\n",a[i]);
}
}
else
{
printf("Data cannot be inserted.");
}
return 0;
}

OUTPUT:
Delete
#include <stdio.h>

int main()
{
int a[100],position,i,size;

printf("Enter number of elements in array. ");


scanf("%d",&size);

printf("\nEnter %d elements\n",size);
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the location where you wish to delete element\n");
scanf("%d",&position);
if(position >= size+1)
{
printf("Deletion not possible.\n");
}

else
{
for (i=position- 1;i<size-1;i++)
{
a[i]=a[i+1];
}
printf("Resultant array:\n");
for(i=0;i<size-1;i++)
{
printf("%d\n",a[i]);
}

return 0;
}
OUTPUT:
Program to perform operations on singly linked list
Search
#include<stdio.h>
#include<stdlib.h>

int main()
{
int n=0;
struct node
{
int data;
struct node *next;
};

struct node *head=0,*newnode,*temp;


int choice=1,num,index=0;

while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter the data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to add more node(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\nEnter the data to be searched.");
scanf("%d",&num);
temp=head;
while(temp!=0)
{
if(temp->data==num)
{
index++;
n=1;
break;
}
else
{
temp=temp->next;
index++;
}
}
if(n==1)printf("Element found at %d position",index);
else printf("element not found");
return 0;
}

OUTPUT:
Insert
at beginning
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *next;
};
struct node *head=0, *newnode, *temp;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to insert a newnode(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0){
printf("%d ",temp->data);
temp=temp->next;}
newnode=(struct node*)malloc(sizeof (struct node));
printf("\nEnter the data to be inserted ");
scanf("%d",&newnode->data);
newnode->next=head;
head=newnode;
temp=head;
while(temp!=0)
{printf("%d ",temp->data);
temp=temp->next;}
}

OUTPUT:
At the end
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *next;
};
struct node *head=0, *newnode, *temp;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to insert a new node(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
newnode=(struct node*)malloc(sizeof (struct node));
printf("\nEnter the data to be inserted ");
scanf("%d",&newnode->data);
newnode->next=0;
temp=head;
while(temp->next!=0)
{
temp=temp->next;
}
temp->next=newnode;
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}

OUTPUT:
At any position

#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *next;
};
struct node *head=0, *newnode, *temp;
int choice=1,position,i=1,count=0;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to insert a new node(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
newnode=(struct node*)malloc(sizeof (struct node));
temp = head;

while(temp != NULL)
{
count++;
temp = temp->next;
}
printf("Total number of elements are %d",count);
printf("\nEnter the position where data is to be inserted. ");
scanf("%d",&position);
if(position>count)
{
printf("Invalid position");
}
else
{
temp=head;
while(i<position)
{
temp=temp->next;
i++;
}
printf("\nEnter the data to be inserted ");
scanf("%d",&newnode->data);
newnode->next=temp->next;
temp->next=newnode;
temp=head;
}
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}

OUTPUT:
Delete
At Beginning

#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *next;
};
struct node *head=0, *newnode, *temp;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to insert a new node(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
temp=head;
head=head->next;
free(temp);
printf("\n Deletion successful\n");
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next; }
OUTPUT:
At the end

#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *next;
};
struct node *head=0, *newnode,*prevnode, *temp;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to insert a new node(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
temp=head;
while(temp->next!=0)
{
prevnode=temp;
temp=temp->next;
}
if(temp==head)
{
head=0;
free(temp);
}
else
{
prevnode->next=0;
free(temp);
}
printf("\n Deletion successful");
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
}

OUTPUT:
At any position

#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{ int data;
struct node *next;
};
struct node *head=0, *newnode, *nextnode, *temp;
int choice=1,position,i=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
newnode->next=0;
if(head==0)
{ head=temp=newnode;
}
else
{ temp->next=newnode;
temp=newnode;
}
printf("Do you want to insert a new node(0,1)? ");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{ printf("%d ",temp->data);
temp=temp->next;
}
temp=head;
printf("\nEnter position ");
scanf("%d",&position);
while(i<position-1)
{ temp=temp->next;
i++;
}
nextnode=temp->next;
temp->next=nextnode->next;
free(nextnode);
temp=head;
while(temp!=0)
{ printf("%d ",temp->data);
temp=temp->next;}
}
OUTPUT:
Program to perform operations on doubly linked list
Search
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *prev;
struct node *next;
};
struct node *head=0,*tail,*newnode,*temp;
int choice=1,index=0,num,n;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{
head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{
tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\nEnter the data to be searched.");
scanf("%d",&num);
temp=head;
while(temp!=0)
{
if(temp->data==num)
{
index++;
n=1;
break;
}
else
{
temp=temp->next;
index++;
}
}
if(n==1)printf("Element found at %d position",index);
else printf("element not found");
return 0;
}
OUTPUT:

Insert
At beginning
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *prev;
struct node *next;
};
struct node *head=0,*tail,*newnode,*temp;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{
head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{
tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
struct node *ptr;
int item;
ptr = (struct node *)malloc(sizeof(struct node));
if(ptr == NULL)
{
printf("\nOVERFLOW");
}
else
{
printf("\nEnter Item value");
scanf("%d",&item);

if(head==NULL)
{
ptr->next = NULL;
ptr->prev=NULL;
ptr->data=item;
head=ptr;
}
else
{
ptr->data=item;
ptr->prev=NULL;
ptr->next = head;
head->prev=ptr;
head=ptr;
}
printf("\nNode inserted\n");
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
}
}

OUTPUT:
At end
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
struct node *prev;
struct node *next;
int data;
};
struct node *ptr,*temp,*head=0,*tail,*newnode;
int item;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{
head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{
tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
ptr=(struct node*)malloc(sizeof (struct node));
if(ptr == NULL)
{
printf("\nOVERFLOW");
}
else
{
printf("\nEnter value");
scanf("%d",&item);
ptr->data=item;
if(head == NULL)
{
ptr->next = NULL;
ptr->prev = NULL;
head = ptr;
}
else
{
temp = head;
while(temp->next!=NULL)
{
temp = temp->next;
}
temp->next = ptr;
ptr ->prev=temp;
ptr->next = NULL;
}
}
printf("\nnode inserted\n");
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
}

OUTPUT:
At any position
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *prev;
struct node *next;
};
struct node *head=0,*tail,*newnode,*temp;
int choice=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{
head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{
tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}

int pos,i=1;
newnode = (struct node *)malloc(sizeof(struct node));
temp=head;
printf("Enter the location");
scanf("%d",&pos);
if(pos==1)
{
printf("Insertion invalid");
}
else
{
while(i<pos-1)
{
temp = temp->next;
i++;
}
printf("Enter value");
scanf("%d",&newnode->data);
newnode->prev=temp;
newnode->next=temp->next;
temp->next=newnode;
newnode->next->prev=newnode;
printf("\nnode inserted\n");
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
}
OUTPUT:

Delete
At beginning
#include<stdio.h>
#include<stdlib.h>
int main()
{struct node
{ int data;
struct node *prev;
struct node *next;
};
struct node *head=0,*tail,*newnode,*temp;
int choice=1,i=1;
while(choice)
{newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{printf("%d ",temp->data);
temp=temp->next;}
temp=head;
head=head->next;
head->prev=0;
free(temp);
printf("Node has been deleted");
temp=head;
printf("\nNew list is\n");
while(temp!=0)
{ printf("%d ",temp->data);
temp=temp->next;
}
}

OUTPUT:

At the end
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{ int data;
struct node *prev;
struct node *next;
};
struct node *head=0,*tail,*newnode,*temp;
int choice=1,pos,i=1,count=0;
while(choice)
{newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{ tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{ printf("%d ",temp->data);
temp=temp->next;
}
temp=tail;
tail->prev->next=0;
tail=tail->prev;
free(temp);
temp=head;
printf("\nNew List is\n");
while(temp!=0)
{printf("%d ",temp->data);
temp=temp->next;
}
}

OUTPUT:

At any position
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct node
{
int data;
struct node *prev;
struct node *next;
};
struct node *head=0,*tail,*newnode,*temp;
int choice=1,pos,i=1;
while(choice)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter data ");
scanf("%d",&newnode->data);
if(head==0)
{
head=tail=newnode;
head->prev=0;
tail->next=0;
}
else
{
tail->next=newnode;
newnode->prev=tail;
tail=newnode;
tail->next=0;
}
printf("Do you want to add a new node(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\nEnter position of data to be deleted");
scanf("%d",&pos);
temp=head;
while(i<pos)
{
temp=temp->next;
i++;
}
temp->prev->next=temp->next;
temp->next->prev=temp->prev;
free(temp);
printf("Deletion sucessful\n");
temp=head;
printf("New list is");
while(temp!=0)
{
printf("%d ",temp->data);
temp=temp->next;
}
}

OUTPUT:
Program to implement operation on circular linked list:
Search
#include <stdio.h>
#include <stdlib.h>
struct node {
int num;
struct node * nextptr;
}*stnode,*ennode;

void ClListcreation(int n);


int FindElement(int FindElem, int n);
void displayClList();
int main()
{int n,m;
int i,FindElem,FindPlc;
stnode = NULL;
ennode = NULL;
printf("\n\n Circular Linked List : Search an element in a circular linked list :\n");
printf("-------------------------------------------------------------------------\n");
printf(" Input the number of nodes : ");
scanf("%d", &n);
m=n;

ClListcreation(n);
displayClList();
printf(" Input the element you want to find : ");
scanf("%d", &FindElem);

FindPlc=FindElement(FindElem,m);
if(FindPlc<n)
printf(" Element found at node %d \n\n",FindPlc);
else
printf(" This element does not exists in linked list.\n\n");
return 0;
}

void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;
if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node 1 : ");
scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}

int FindElement(int FindElem, int a)


{
int ctr=1;
ennode=stnode;
while(ennode->nextptr!=NULL)
{
if(ennode->num==FindElem)
break;
else
ctr++;
ennode=ennode->nextptr;
if (ctr==a+1)
break;
}
return ctr;
}

void displayClList()
{
struct node *tmp;
int n = 1;
if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
printf("\n\n Data entered in the list are :\n");
do {
printf(" Data %d = %d\n", n, tmp->num);
tmp = tmp->nextptr;
n++;
}while(tmp != stnode);
}
}

OUTPUT:

Insertion
At the begining
#include <stdio.h>
#include <stdlib.h>
struct node {
int num;
struct node * nextptr;
}*stnode;

void ClListcreation(int n);


void ClLinsertNodeAtBeginning(int num);
void displayClList(int a);

int main()
{
int n,num1,a;
stnode = NULL;
printf("\n\n Circular Linked List : Insert a node at the beginning of a circular linked
list :\n");
printf("--------------------------------------------------------------------------------------\n");
printf(" Input the number of nodes : ");
scanf("%d", &n);
ClListcreation(n);
a=1;
displayClList(a);
printf(" Input data to be inserted at the beginning : ");
scanf("%d", &num1);
ClLinsertNodeAtBeginning(num1);
a=2;
displayClList(a);
return 0;
}
void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;

if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));

printf(" Input data for node 1 : ");


scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}

void ClLinsertNodeAtBeginning(int num)


{
struct node *newnode, *curNode;
if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
newnode = (struct node *)malloc(sizeof(struct node));
newnode->num = num;
newnode->nextptr = stnode;
curNode = stnode;
while(curNode->nextptr != stnode)
{
curNode = curNode->nextptr;
}
curNode->nextptr = newnode;
stnode = newnode;
}
}
void displayClList(int m)
{
struct node *tmp;
int n = 1;

if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
if (m==1)
{
printf("\n Data entered in the list are :\n");
}
else
{
printf("\n After insertion the new list are :\n");
}
do {
printf(" Data %d = %d\n", n, tmp->num);
tmp = tmp->nextptr;
n++;
}while(tmp != stnode);}
}

OUTPUT:

At the end
#include <stdio.h>
#include <stdlib.h>

struct node {
int num;
struct node * nextptr;
}*stnode;

struct node *tail,*p,*q,*store;

void ClListcreation(int n);


void ClLinsertNodeAtEnd(int num);
void displayClList(int a);

int main()
{
int n,num1,a,insPlc;
stnode = NULL;
printf("\n\n Circular Linked List : Insert a node at the end of a circular linked list :\
n");
printf("--------------------------------------------------------------------------------\n");
printf(" Input the number of nodes : ");
scanf("%d", &n);
ClListcreation(n);
a=1;
displayClList(a);
printf(" Input the data to be inserted : ");
scanf("%d", &num1);
ClLinsertNodeAtEnd(num1);
a=2;
displayClList(a);
return 0;
}

void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;
if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node 1 : ");
scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}

void ClLinsertNodeAtEnd(int num1)


{
int a;
a=num1;
struct node *temp=(struct node*)malloc(sizeof(struct node));
temp->num=a;
p=stnode;
while(p->nextptr!=stnode)
{
p=p->nextptr;
}
p->nextptr=temp;
temp->nextptr=stnode;
}

void displayClList(int m)
{
struct node *tmp;
int n = 1;
if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
if (m==1)
{
printf("\n Data entered in the list are :\n");
}
else
{
printf("\n After insertion the new list are :\n");
}
do {
printf(" Data %d = %d\n", n, tmp->num);

tmp = tmp->nextptr;
n++;
}while(tmp != stnode);
}
}

OUTPUT:
At any position in mid
#include <stdio.h>
#include <stdlib.h>

struct node {
int num;
struct node * nextptr;
}*stnode;

void ClListcreation(int n);


void ClLinsertNodeAtBeginning(int num);
void ClLinsertNodeAtAny(int num, int pos);
void displayClList(int a);

int main()
{
int n,num1,a,insPlc;
stnode = NULL;
printf("\n\n Circular Linked List : Insert a node at any position in a circular linked list
:\n");
printf("--------------------------------------------------------------------------------------\n");

printf(" Input the number of nodes : ");


scanf("%d", &n);
ClListcreation(n);
a=1;
displayClList(a);
printf(" Input the position to insert a new node : ");
scanf("%d", &insPlc);
printf(" Input data for the position %d : ", insPlc);
scanf("%d", &num1);
ClLinsertNodeAtAny(num1,insPlc);
a=2;
displayClList(a);
return 0;
}

void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;

if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));

printf(" Input data for node 1 : ");


scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}

void ClLinsertNodeAtBeginning(int num)


{
struct node *newnode, *curNode;

if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
newnode = (struct node *)malloc(sizeof(struct node));
newnode->num = num;
newnode->nextptr = stnode;
curNode = stnode;
while(curNode->nextptr != stnode)
{
curNode = curNode->nextptr;
}
curNode->nextptr = newnode;
stnode = newnode;
}
}

void ClLinsertNodeAtAny(int num, int pos)


{
struct node *newnode, *curNode;
int i;
if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else if(pos == 1)
{
ClLinsertNodeAtBeginning(num);
}
else
{
newnode = (struct node *)malloc(sizeof(struct node));
newnode->num = num;
curNode = stnode;
for(i=2; i<=pos-1; i++)
{
curNode = curNode->nextptr;
}
newnode->nextptr = curNode->nextptr;
curNode->nextptr = newnode;
}
}

void displayClList(int m)
{
struct node *tmp;
int n = 1;
if(stnode == NULL)
{printf(" No data found in the List yet.");
}
else
{tmp = stnode;
if (m==1)
{printf("\n Data entered in the list are :\n");
}
else
{printf("\n After insertion the new list are :\n");
}
do {printf(" Data %d = %d\n", n, tmp->num);

tmp = tmp->nextptr;
n++; }while(tmp != stnode);
}
}

OUTPUT:
Delete
At beginning
#include <stdio.h>
#include <stdlib.h>

struct node {
int num;
struct node * nextptr;
}*stnode;

struct node *tail,*p,*q,*store;

void ClListcreation(int n);


void ClListDeleteFirstNode();
void displayClList(int a);

int main()
{
int n,num1,a,insPlc;
stnode = NULL;
printf("\n\n Circular Linked List : Delete node from the beginning of a circular linked
list :\n");
printf("--------------------------------------------------------------------------------------\n");

printf(" Input the number of nodes : ");


scanf("%d", &n);
ClListcreation(n);
a=1;
displayClList(a);
ClListDeleteFirstNode();
a=2;
displayClList(a);
return 0;
}

void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;

if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));

printf(" Input data for node 1 : ");


scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}
void ClListDeleteFirstNode()
{
p=stnode;
while(p->nextptr!=stnode)
{
p=p->nextptr;
}
store=stnode;
stnode=stnode->nextptr;
printf("\n The deleted node is -> %d",store->num);
p->nextptr=stnode;
free (store);
}

void displayClList(int m)
{
struct node *tmp;
int n = 1;

if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
if (m==1)
{
printf("\n Data entered in the list are :\n");
}
else
{
printf("\n After deletion the new list are :\n");
}
do {
printf(" Data %d = %d\n", n, tmp->num);

tmp = tmp->nextptr;
n++;
}while(tmp != stnode);
}
}

OUTPUT:
At the end
#include <stdio.h>
#include <stdlib.h>

struct node {
int num;
struct node * nextptr;
}*stnode;

struct node *tail,*p,*q,*store;

void ClListcreation(int n);


void ClListDeleteLastNode();
void displayClList(int a);

int main()
{
int n,num1,a,pos;
stnode = NULL;
printf("\n\n Circular Linked List : Delete node at the end of a circular linked list :\n");
printf("--------------------------------------------------------------------------------\n");

printf(" Input the number of nodes : ");


scanf("%d", &n);
ClListcreation(n);
a=1;
displayClList(a);
ClListDeleteLastNode();
a=2;
displayClList(a);
return 0;
}

void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;

if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));

printf(" Input data for node 1 : ");


scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}
void ClListDeleteLastNode()
{
p=stnode;
while(p->nextptr!=stnode)
{
q=p;
p=p->nextptr;
}
q->nextptr=stnode;
printf("\n The deleted node is : %d",p->num);
free(p);
}

void displayClList(int m)
{
struct node *tmp;
int n = 1;

if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
if (m==1)
{
printf("\n Data entered in the list are :\n");
}
else
{
printf("\n After deletion the new list are :\n");
}
do {
printf(" Data %d = %d\n", n, tmp->num);

tmp = tmp->nextptr;
n++;
}while(tmp != stnode);
}
}

OUTPUT:
At any position in the mid
#include <stdio.h>
#include <stdlib.h>

struct node {
int num;
struct node * nextptr;
}*stnode;

struct node *tail,*p,*q,*store;

void ClListcreation(int n);


void ClListDeleteMiddle(int pos);
void displayClList(int a);

int main()
{
int n,num1,a,pos;
stnode = NULL;
printf("\n\n Circular Linked List : Delete node from the middle of a circular linked list
:\n");
printf("-----------------------------------------------------------------------------------\n");

printf(" Input the number of nodes : ");


scanf("%d", &n);
ClListcreation(n);
a=1;
displayClList(a);
printf("\n Input the position to delete the node : ");
scanf("%d",&pos);
ClListDeleteMiddle(pos);
a=2;
displayClList(a);
return 0;
}

void ClListcreation(int n)
{
int i, num;
struct node *preptr, *newnode;

if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));

printf(" Input data for node 1 : ");


scanf("%d", &num);
stnode->num = num;
stnode->nextptr = NULL;
preptr = stnode;
for(i=2; i<=n; i++)
{
newnode = (struct node *)malloc(sizeof(struct node));
printf(" Input data for node %d : ", i);
scanf("%d", &num);
newnode->num = num;
newnode->nextptr = NULL;
preptr->nextptr = newnode;
preptr = newnode;
}
preptr->nextptr = stnode;
}
}

void ClListDeleteMiddle(int pos)


{
int delNode,k=1;
delNode=pos;
p=stnode;
while(k!=delNode)
{
q=p;
p=p->nextptr;
k++;
}
q->nextptr=p->nextptr;
printf("\n The deleted node is : %d",p->num);
free(p);
}

void displayClList(int m)
{
struct node *tmp;
int n = 1;

if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
if (m==1)
{
printf("\n Data entered in the list are :\n");
}
else
{
printf("\n After deletion the new list are :\n");
}
do {
printf(" Data %d = %d\n", n, tmp->num);

tmp = tmp->nextptr;
n++;
}while(tmp != stnode);
}
}

OUTPUT
Program to implement push and pop operation in Stack
using
Array
#include<stdio.h>
int stack[100],choice,n,top,x,i;
void push(void);
void pop(void);
void display(void);
int main()
{
//clrscr();
top=-1;
printf("\n Enter the size of STACK[MAX=100]:");
scanf("%d",&n);
printf("\n\t STACK OPERATIONS USING ARRAY");
printf("\n\t--------------------------------");
printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY\n\t 4.EXIT");
do
{
printf("\n Enter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:
{
printf("\n\t EXIT POINT ");
break;
}
default:
{
printf ("\n\t Please Enter a Valid Choice(1/2/3/4)");
}

}
}
while(choice!=4);
return 0;
}
void push()
{
if(top>=n-1)
{
printf("\n\tSTACK is over flow");

}
else
{
printf(" Enter a value to be pushed:");
scanf("%d",&x);
top++;
stack[top]=x;
}
}
void pop()
{
if(top<=-1)
{
printf("\n\t Stack is under flow");
}
else
{
printf("\n\t The popped elements is %d",stack[top]);
top--;
}
}
void display()
{
if(top>=0)
{
printf("\n The elements in STACK \n");
for(i=top; i>=0; i--)
printf("%d ",stack[i]);
printf("\n Press Next Choice");
}
else
{
printf("\n The STACK is empty");
}

OUTPUT:
Linked list
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

struct Node
{
int data;
struct Node *next;
}*top = NULL;

void push(int);
void pop();
void display();

void main()
{
int choice, value;
while(1){
printf("1. Push\n2. Pop\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the value to be insert: ");
scanf("%d", &value);
push(value);
break;
case 2: pop(); break;
case 3: display(); break;
case 4: exit(0);
default: printf("\nWrong selection!!! Please try again!!!\n");
}
}
}
void push(int value)
{
struct Node *newNode;
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
if(top == NULL)
newNode->next = NULL;
else
newNode->next = top;
top = newNode;
printf("\nInsertion is Success!!!\n");
}
void pop()
{
if(top == NULL)
printf("\nStack is Empty!!!\n");
else{
struct Node *temp = top;
printf("\nDeleted element: %d", temp->data);
top = temp->next;
free(temp);
}
}
void display()
{
if(top == NULL)
printf("\nStack is Empty!!!\n");
else{
struct Node *temp = top;
while(temp->next != NULL){
printf("%d--->",temp->data);
temp = temp -> next;
}
printf("%d--->NULL",temp->data);
}
}

OUTPUT:
Programs to implement enqueue and dequeue operation in
Queue using:
Array
#include <stdio.h>
#define MAX 10
int QUEUE[MAX],front=-1,rear=-1;
void enqueue(int queue[],int ele)
{
if(rear==-1)
{
front=rear=0;
queue[rear]=ele;
}
else if(rear==MAX-1)
{
printf("\nQueue is full.\n");
return;
}
else
{
rear++;
queue[rear]=ele;
}

void display(int queue[])


{
int i;
if(rear==-1)
{ printf("\nQUEUE is Empty.");
return;
}
printf("Elements in queue are\n");
for(i=front;i<=rear;i++)
{
printf("%d ,",queue[i]);
}

void dequeue(int queue[])


{
int ele;
if(front==-1)
{
printf("Queue is Empty.");
return;
}
else if(front==rear)
{
ele=queue[front];
front=rear=-1;
}
else
{
ele=queue[front];
front++;
}
printf("\nItem deleted: %d.",ele);
}

int main()
{
int ele,choice;
do
{

printf("\n1.Insert\n2.Display\n3.Delete\n4.Exit\n");
printf("Enter your choice");
scanf("%d",&choice);
switch(choice)
{

case 1:
printf("Enter an element to insert:");
scanf("%d",&ele);
enqueue(QUEUE,ele);
break;
case 2:
display(QUEUE);
break;
case 3:
dequeue(QUEUE);
break;
}
}
while(choice!=4);

}
OUTPUT:
Linked list
#include<stdio.h>
#include<stdlib.h>
struct node
{int data;
struct node* next;
};
struct node* front=0;
struct node* rear=0;
void enqueue(int ele)
{struct node* newnode;
newnode=(struct node*)malloc(sizeof(struct node));
newnode->data=ele;
newnode->next=NULL;
if(front==0 && rear==0)
{front=rear=newnode;
}
else
{rear->next=newnode;
rear=newnode;
}
}
void display()
{struct node* temp;
temp=front;
if(front==0&&rear==0)
printf("Queue is empty \n");
else
{
while(temp!=0)
{printf("%d ",temp->data);
temp=temp->next;
}
}
}
void dequeue()
{
struct node* temp;
temp=front;
if(front==0&&rear==0)
{
printf("queue is empty \n");
}
else
{
front=temp->next;
free(temp);
}
}
int main()
{
int choice,ele;
do
{printf("\noptions available \n");
printf("1. enqueue 2. display 3. dequeue \n");
printf("Enter your choice \n");
scanf("%d",&choice);
switch(choice)
{case 1: printf("Enter the element \n");
scanf("%d",&ele);
enqueue(ele);
break;
case 2: display();
break;
case 3: dequeue();
break;
}
}
while(choice!=4);
}

OUTPUT:
Program to implement push and pop operation from front
and rear end in a DeQue using:
Array
#include<stdio.h>
#include<conio.h>
#define MAX 10
int deque[MAX];
int left=-1, right=-1;
void insert_right(void);
void insert_left(void);
void delete_right(void);
void delete_left(void);
void display(void);
int main()
{
int choice;
do
{printf("1.Insert at right ");
printf("2.Insert at left ");
printf("3.Delete from right ");
printf("4.Delete from left ");
printf("5.Display ");
printf("6.Exit");
printf("\nEnter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:insert_right();
break;
case 2:insert_left();
break;
case 3:delete_right();
break;
case 4:delete_left();
break;
case 5:display();
break;
}
}while(choice!=6);
getch();
return 0;
}
void insert_right()
{int val;
printf("Enter the value to be added ");
scanf("%d",&val);
if( (left==0 && right==MAX-1) || (left==right+1) )
{printf("\nOVERFLOW");
}
if(left==-1)
{
left=0;
right=0;
}
else
{
if(right==MAX-1)
right=0;
else
right=right+1;
}
deque[right]=val;
}
void insert_left()
{int val;
printf("\nEnter the value to be added ");
scanf("%d",&val);
if( (left==0 && right==MAX-1) || (left==right+1) )
{printf("\nOVERFLOW");
}
if(left==-1)
{left=0;
right=0;
}
else
{if(left==0)
left=MAX-1;
else
left=left-1;
}
deque[left]=val;
}
void delete_right()
{
if(left==-1)
{printf("\nUNDERFLOW");
return;
}
printf("\nThe deleted element is %d\n", deque[right]);
if(left==right)
{left=-1;
right=-1;
}
else
{if(right==0)
right=MAX-1;
else
right=right-1;}}
void delete_left()
{
if(left==-1)
{printf("\nUNDERFLOW");
return;
}
printf("\nThe deleted element is %d\n", deque[left]);
if(left==right)
{left=-1;
right=-1;
}
else
{if(left==MAX-1)
left=0;
else
left=left+1;}}
void display()
{int front=left, rear=right;
if(front==-1)
{printf("\nQueue is Empty\n");
return;}
printf("\nThe elements in the queue are: ");
if(front<=rear)
{while(front<=rear)
{printf("%d\t",deque[front]);
front++;}}
else
{
while(front<=MAX-1)
{printf("%d\t",deque[front]);
front++;
}
front=0;
while(front<=rear)
{printf("%d\t",deque[front]);
front++;}}
printf("\n");
}

OUTPUT:
Linked list:
#include <stdio.h>
#include <stdlib.h>

struct node {
int data;
struct node *prev, *next;
};

struct node *head = NULL, *tail = NULL;

struct node * createNode(int data) {


struct node *newnode = (struct node *)malloc(sizeof (struct node));
newnode->data = data;
newnode->next = newnode->prev = NULL;
return (newnode);
}

void createSentinels() {
head = createNode(0);
tail = createNode(0);
head->next = tail;
tail->prev = head;
}

void enqueueAtFront(int data) {


struct node *newnode, *temp;
newnode = createNode(data);
temp = head->next;
head->next = newnode;
newnode->prev = head;
newnode->next = temp;
temp->prev = newnode;
}

void enqueueAtRear(int data) {


struct node *newnode, *temp;
newnode = createNode(data);
temp = tail->prev;
tail->prev = newnode;
newnode->next = tail;
newnode->prev = temp;
temp->next = newnode;
}

void dequeueAtFront() {
struct node *temp;
if (head->next == tail) {
printf("Queue is empty\n");
} else {
temp = head->next;
head->next = temp->next;
temp->next->prev = head;
free(temp);
}
return;
}

void dequeueAtRear() {
struct node *temp;
if (tail->prev == head) {
printf("Queue is empty\n");
} else {
temp = tail->prev;
tail->prev = temp->prev;
temp->prev->next = tail;
free(temp);
}
return;
}

void display() {
struct node *temp;

if (head->next == tail) {
printf("Queue is empty\n");
return;
}

temp = head->next;
while (temp != tail) {
printf("%-3d", temp->data);
temp = temp->next;
}
printf("\n");
}

int main() {
int data, ch;
createSentinels();
while (1) {
printf("1.Insert from left 2.Insert from right ");
printf("3.Delete from left 4.Delete from right ");
printf("5.Display 6.Exit\n");
printf("Enter your choice:");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("Enter the data to insert:");
scanf("%d", &data);
enqueueAtFront(data);
break;

case 2:
printf("Enter ur data to insert:");
scanf("%d", &data);
enqueueAtRear(data);
break;

case 3:
dequeueAtFront();
break;

case 4:
dequeueAtRear();
break;

case 5:
display();
break;

case 6:
exit(0);

default:
printf("Pls. enter correct option\n");
break;
}
}
return 0;
}

OUTPUT:
Program to implement push and pop operation in
Circular Queue using:
Array
# include<stdio.h>
# define MAX 5

int queue[MAX];
int front = -1;
int rear = -1;

void insert(int item)


{
if((front == 0 && rear == MAX-1) || (front == rear+1))
{
printf("Queue Overflow \n");
return;
}
if (front == -1)
{
front = 0;
rear = 0;
}
else
{
if(rear == MAX-1)
rear = 0;
else
rear = rear+1;
}
queue[rear] = item ;
}

void del()
{
if (front == -1)
{
printf("Queue Underflow\n");
return ;
}
printf("Element deleted: %d\n",queue[front]);
if(front == rear)
{
front = -1;
rear=-1;
}
else
{
if(front == MAX-1)
front = 0;
else
front = front+1;
}
}

void display()
{
int temp1 = front,temp2= rear;
if(front == -1)
{
printf("Queue is empty\n");
return;
}
printf("Queue elements :\n");
if( temp1 <= temp2 )
while(temp1 <= temp2)
{
printf("%d ",queue[temp1]);
temp1=temp1+1;
}
else
{
while(temp1<= MAX-1)
{
printf("%d ",queue[temp1]);
temp1=temp1+1;
}
temp1 = 0;
while(temp1<= temp2)
{
printf("%d ",queue[temp1]);
temp1=temp1+1;
}
}
printf("\n");
}

int main()
{
int choice,item;
do
{
printf("1.Insert\n2.Delete\n3.Display\n4.Exit");
printf("Enter your choice ");
scanf("%d",&choice);

switch(choice)
{
case 1 :
printf("Input the element : ");
scanf("%d", &item);
insert(item);
break;

case 2 :
del();
break;

case 3:
display();
break;

case 4:
break;

default:
printf("Wrong choice\n");
}
}
while(choice!=4);
}
OUTPUT:
Linked List:

#include<stdio.h>
#include<stdlib.h>

struct Node
{
int data;
struct Node *next;
}*front = NULL, *rear = NULL;

void enQueue(int value)


{
struct Node *newNode;
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode -> data = value;
newNode -> next = NULL;
if (front == NULL)
front = rear = newNode;
else {
rear -> next = newNode;
rear = newNode;
}
printf("Insertion is Successful\n");
}

void deQueue()
{
if (front == NULL)
printf("\nUnderflow. Queue is Empty\n");
else
{
struct Node *temp = front;
front = front -> next;
printf("\nDeleted element: %d\n", temp -> data);
free(temp);
}
}

void display()
{
if (front == NULL)
printf("\nQueue is Empty!\n");
else {
struct Node *temp = front;
while (temp -> next != NULL) {
printf("%d--->", temp -> data);
temp = temp -> next;
}
printf("%d--->NULL\n", temp -> data);
}
}

void main()
{
int choice, value;
while(1) {
printf("Queue using Linked List\n");
printf("1. Insert 2. Delete 3. Display 4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1: printf("Enter the value to be inserted: ");
scanf("%d", &value);
enQueue(value);
break;
case 2: deQueue();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\nWrong choice. Please try again\n");
}
}
}

OUTPUT:
Program to create Binary Tree and display using in-order
traversal:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* left;
struct node* right;
};
int max(int inorder[], int strt, int end);
struct node* newNode(int data);
struct node* buildTree (int inorder[], int start, int end)
{
if (start > end)
return NULL;
int i = max (inorder, start, end);
struct node *root = newNode(inorder[i]);
if (start == end)
return root;
root->left = buildTree (inorder, start, i-1);
root->right = buildTree (inorder, i+1, end);

return root;
}
int max (int arr[], int strt, int end)
{
int i, max = arr[strt], maxind = strt;
for(i = strt+1; i <= end; i++)
{
if(arr[i] > max)
{
max = arr[i];
maxind = i;
}
}
return maxind;
}
struct node* newNode (int data)
{
struct node* node = (struct node*)malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;

return node;
}
void printInorder (struct node* node)
{
if (node == NULL)
return;
printInorder (node->left);
printf("%d ", node->data);
printInorder (node->right);
}

int main()
{
int inorder[] = {5, 10, 40, 30, 28};
int len = sizeof(inorder)/sizeof(inorder[0]);
struct node *root = buildTree(inorder, 0, len - 1);
printf("\n Inorder traversal of the constructed tree is \n");
printInorder(root);
return 0;
}

OUTPUT:

You might also like