Monday 12 December 2011

Write a program for merging two sorted arrays into third sorted array.


#include<stdio.h>

main()
{
int arr1[20],arr2[20],arr3[40];
int i,j,k;
int max1,max2;

printf("Enter the number of elements in list1 : ");
scanf("%d",&max1);
printf("Take the elements in sorted order :\n");
for(i=0;i<max1;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&arr1[i]);
}
printf("Enter the number of elements in list2 : ");
scanf("%d",&max2);
printf("Take the elements in sorted order :\n");
for(i=0;i<max2;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&arr2[i]);
}
/* Merging */
i=0;   /*Index for first array*/
j=0;   /*Index for second array*/
k=0;   /*Index for merged array*/

while( (i < max1) && (j < max2) )
{
if( arr1[i] < arr2[j] )
arr3[k++]=arr1[i++];
else
arr3[k++]=arr2[j++];
}/*End of while*/
/*Put remaining elements of arr1 into arr3*/
while( i < max1 )
arr3[k++]=arr1[i++];
/*Put remaining elements of arr2 into arr3*/
while( j < max2 )
arr3[k++]=arr2[j++];

/*Merging completed*/
printf("List 1 :  ");
for(i=0;i<max1;i++)
printf("%d ",arr1[i]);
printf("\nList 2 :  ");
for(i=0;i<max2;i++)
printf("%d ",arr2[i]);
printf("\nMerged list : ");
for(i=0;i<max1+max2;i++)
printf("%d ",arr3[i]);
printf("\n");
}/*End of main()*/

Write a program for insertion sort.


#include <stdio.h>
#define MAX 20

main()
{
int arr[MAX],i,j,k,n;
printf("Enter the number of elements : ");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
printf("Enter element %d : ",i+1);
scanf("%d", &arr[i]);
}
printf("Unsorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
/*Insertion sort*/
for(j=1;j<n;j++)
{
k=arr[j]; /*k is to be inserted at proper place*/
for(i=j-1;i>=0 && k<arr[i];i--)
arr[i+1]=arr[i];
arr[i+1]=k;
printf("Pass %d, Element inserted in proper place: %d\n",j,k);
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
printf("Sorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}/*End of main()*/



Write a program for bubble sort using arrays.


#include <stdio.h>
#define MAX 20
main()
{
int arr[MAX],i,j,k,temp,n,xchanges;
printf("Enter the number of elements : ");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&arr[i]);
}
printf("Unsorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");

/* Bubble sort*/
for (i = 0; i < n-1 ; i++)
{
xchanges=0;
for (j = 0; j <n-1-i; j++)
{
if (arr[j] > arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
xchanges++;
}/*End of if*/
}/*End of inner for loop*/
if(xchanges==0) /*If list is sorted*/
break;
printf("After Pass %d elements are :  ",i+1);
for (k = 0; k < n; k++)
printf("%d ", arr[k]);
printf("\n");
}/*End of outer for loop*/

printf("Sorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}/*End of main()*/

Write a program fo binary search.



#include <stdio.h>

main()
{
int arr[20],start,end,middle,n,i,item;

printf("How many elements you want to enter in the array : ");
scanf("%d",&n);
for(i=0; i < n; i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&arr[i]);
}
printf("Enter the element to be searched : ");
scanf("%d",&item);
start=0;
end=n-1;
middle=(start+end)/2;
while(item != arr[middle] && start <= end)
{
if(item > arr[middle])
start=middle+1;
else
end=middle-1;
middle=(start+end)/2;
}
if(item==arr[middle])
printf("%d found at position %d\n",item,middle+1);
if(start>end)
printf("%d not found in array\n",item);
}/*End of main()*/


WAP to implement the concept of sequential search.


# include<stdio.h>

main()
{
int arr[20],n,i,item;
printf("How many elements you want to enter in the array : ");
scanf("%d",&n);

for(i=0; i < n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d", &arr[i]);
}
printf("Enter the element to be searched : ");
scanf("%d",&item);
for(i=0;i < n;i++)
{
if(item == arr[i])
{
printf("%d found at position %d\n",item,i+1);
break;
}
}/*End of for*/
if(i == n)
printf("Item %d not found in array\n",item);

}

WAP to implement the concept of sorted linked list.


# include <stdio.h>
# include <malloc.h>

struct node
{
int info;
struct node *link;
}*start;

main()
{
int choice,n,m,i;
start=NULL;
while(1)
{
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display \n");
printf("4.Exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the element to be inserted : ");
scanf("%d",&m);
insert(m);
break;
case 2:
printf("Enter the element to be deleted : ");
scanf("%d",&m);
del(m);
break;
case 3:
display();
break;
case 4:
exit();
default:
printf("Wrong choice\n");
}/*End of switch*/
}/*End of while*/
} /*end of main */

insert(int num)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=num;

/*list empty or item to be added in begining */
if(start == NULL || num < start->info)
{
tmp->link=start;
start=tmp;
return;
}
else
{
q=start;
while(q->link != NULL && q->link->info < num)
q=q->link;
tmp->link=q->link;
q->link=tmp;
}
}/*End of insert()*/

del(int num)
{
struct node *tmp,*q;
if(start->info==num)
{
tmp=start;
start=start->link;  /*first element deleted*/
free(tmp);
return;
}
q=start;
while(q->link->link!=NULL)
{
if(q->link->info==num)     /*element deleted in between*/
{
tmp=q->link;
q->link=tmp->link;
free(tmp);
return;
}
q=q->link;
}/*End of while */
if(q->link->info==num)    /*last element deleted*/
{
tmp=q->link;
free(tmp);
q->link=NULL;
return;
}
printf("Element %d not found\n",num);
}/*End of del()*/

display()
{
struct node *q;
if(start == NULL)
{
printf("List is empty\n");
return;
}
q=start;
printf("List is :\n");
while(q != NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
}/*End of display() */

WAP to implement the concept of reversed linked list.


# include <stdio.h>
# include <malloc.h>

struct node
{
int info;
struct node *link;
}*start;

main()
{
int i,n,item;
start=NULL;

printf("How many nodes you want : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the item %d : ",i+1);
scanf("%d",&item);
create_list(item);
}
printf("Initially the linked list is :\n");
display();
reverse();
printf("Linked list after reversing is :\n");
display();
}/*End of main()*/

create_list(int num)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=num;
tmp->link=NULL;

if(start==NULL)
start=tmp;
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of create_list() */

display()
{
struct node *q;
if(start == NULL)
{
printf("List is empty\n");
return;
}
q=start;
while(q!=NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
}/*End of display()*/

reverse()
{
struct node *p1,*p2,*p3;
if(start->link==NULL)    /*only one element*/
return;
p1=start;
p2=p1->link;
p3=p2->link;

p1->link=NULL;
p2->link=p1;

while(p3!=NULL)
{
p1=p2;
p2=p3;
p3=p3->link;
p2->link=p1;
}
start=p2;
}/*End of reverse() */

WAP to implement the concept of double linked list.


# include <stdio.h>
# include <malloc.h>

struct node
{
struct node *prev;
int info;
struct node *next;
}*start;

main()
{
int choice,n,m,po,i;
start=NULL;
while(1)
{
printf("1.Create List\n");
printf("2.Add at begining\n");
printf("3.Add after\n");
printf("4.Delete\n");
printf("5.Display\n");
printf("6.Count\n");
printf("7.Reverse\n");
printf("8.exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("How many nodes you want : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list(m);
}
break;
case 2:
printf("Enter the element : ");
scanf("%d",&m);
addatbeg(m);
break;
case 3:
printf("Enter the element : ");
scanf("%d",&m);
printf("Enter the position after which this element is inserted : ");
scanf("%d",&po);
addafter(m,po);
break;
case 4:
printf("Enter the element for deletion : ");
scanf("%d",&m);
del(m);
break;
case 5:
display();
break;
case 6:
count();
break;
case 7:
rev();
break;
case 8:
exit();
default:
printf("Wrong choice\n");
}/*End of switch*/
   }/*End of while*/
}/*End of main()*/

create_list(int num)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=num;
tmp->next=NULL;
if(start==NULL)
{
tmp->prev=NULL;
start->prev=tmp;
start=tmp;
}
else
{
q=start;
while(q->next!=NULL)
q=q->next;
q->next=tmp;
tmp->prev=q;
}
}/*End of create_list()*/

addatbeg(int num)
{
struct node *tmp;
tmp=malloc(sizeof(struct node));
tmp->prev=NULL;
tmp->info=num;
tmp->next=start;
start->prev=tmp;
start=tmp;
}/*End of addatbeg()*/

addafter(int num,int c)
{
struct node *tmp,*q;
int i;
q=start;
for(i=0;i<c-1;i++)
{
q=q->next;
if(q==NULL)
{
printf("There are less than %d elements\n",c);
return;
}
}
tmp=malloc(sizeof(struct node) );
tmp->info=num;
q->next->prev=tmp;
tmp->next=q->next;
tmp->prev=q;
q->next=tmp;
}/*End of addafter() */

del(int num)
{
struct node *tmp,*q;
if(start->info==num)
{
tmp=start;
start=start->next;  /*first element deleted*/
start->prev = NULL;
free(tmp);
return;
}
q=start;
while(q->next->next!=NULL)
{
if(q->next->info==num)     /*Element deleted in between*/
{
tmp=q->next;
q->next=tmp->next;
tmp->next->prev=q;
free(tmp);
return;
}
q=q->next;
}
if(q->next->info==num)    /*last element deleted*/
{ tmp=q->next;
free(tmp);
q->next=NULL;
return;
}
printf("Element %d not found\n",num);
}/*End of del()*/

display()
{
struct node *q;
if(start==NULL)
{
printf("List is empty\n");
return;
}
q=start;
printf("List is :\n");
while(q!=NULL)
{
printf("%d ", q->info);
q=q->next;
}
printf("\n");
}/*End of display() */

count()
{ struct node *q=start;
int cnt=0;
while(q!=NULL)
{
q=q->next;
cnt++;
}
printf("Number of elements are %d\n",cnt);
}/*End of count()*/

rev()
{
struct node *p1,*p2;
p1=start;
p2=p1->next;
p1->next=NULL;
p1->prev=p2;
while(p2!=NULL)
{
p2->prev=p2->next;
p2->next=p1;
p1=p2;
p2=p2->prev; /*next of p2 changed to prev */
}
start=p1;
}/*End of rev()*/

WAP to implement the concept of circular linked list.


# include <stdio.h>
# include <malloc.h>

struct node
{
int info;
struct node *link;
}*last;

main()
{
int choice,n,m,po,i;
last=NULL;
while(1)
{
printf("1.Create List\n");
printf("2.Add at begining\n");
printf("3.Add after \n");
printf("4.Delete\n");
printf("5.Display\n");
printf("6.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("How many nodes you want : ");
scanf("%d",&n);
for(i=0; i < n;i++)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list(m);
}
break;
case 2:
printf("Enter the element : ");
scanf("%d",&m);
addatbeg(m);
break;
case 3:
printf("Enter the element : ");
scanf("%d",&m);
printf("Enter the position after which this element is inserted : ");
scanf("%d",&po);
addafter(m,po);
break;
case 4:
if(last == NULL)
{
printf("List underflow\n");
continue;
}
printf("Enter the number for deletion : ");
scanf("%d",&m);
del(m);
break;
case 5:
display();
break;
case 6:
exit();
default:
printf("Wrong choice\n");
}/*End of switch*/
}/*End of while*/
}/*End of main()*/

create_list(int num)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info = num;

if(last == NULL)
{
last = tmp;
tmp->link = last;
}
else
{
tmp->link = last->link; /*added at the end of list*/
last->link = tmp;
last = tmp;
}
}/*End of create_list()*/

addatbeg(int num)
{
struct node *tmp;
tmp = malloc(sizeof(struct node));
tmp->info = num;
tmp->link = last->link;
last->link = tmp;
}/*End of addatbeg()*/

addafter(int num,int pos)
{

struct node *tmp,*q;
int i;
q = last->link;
for(i=0; i < pos-1; i++)
{
q = q->link;
if(q == last->link)
{
printf("There are less than %d elements\n",pos);
return;
}
}/*End of for*/
tmp = malloc(sizeof(struct node) );
tmp->link = q->link;
tmp->info = num;
q->link = tmp;
if(q==last)    /*Element inserted at the end*/
last=tmp;
}/*End of addafter()*/

del(int num)
{
struct node *tmp,*q;
if( last->link == last && last->info == num)  /*Only one element*/
{
tmp = last;
last = NULL;
free(tmp);
return;
}
q = last->link;
if(q->info == num)
{
tmp = q;
last->link = q->link;
free(tmp);
return;
}
while(q->link != last)
{
if(q->link->info == num)     /*Element deleted in between*/
{
tmp = q->link;
q->link = tmp->link;
free(tmp);
printf("%d deleted\n",num);
return;
}
q = q->link;
}/*End of while*/
if(q->link->info == num)    /*Last element deleted q->link=last*/
{
tmp = q->link;
q->link = last->link;
free(tmp);
last = q;
return;
}
printf("Element %d not found\n",num);
}/*End of del()*/

display()
{
struct node *q;
if(last == NULL)
{
printf("List is empty\n");
return;
}
q = last->link;
printf("List is :\n");
while(q != last)
{
printf("%d ", q->info);
q = q->link;
}
printf("%d\n",last->info);
}/*End of display()*/

WAP to implement the concept of linked list through arrays.


# include<stdio.h>
# define MAX 20

int arr[MAX];
int n;  /*Total number of elements in the list */

main()
{
int  choice,item,pos;
while(1)
{
printf("1.Input list\n");
printf("2.Insert\n");
printf("3.Search\n");
printf("4.Delete\n");
printf("5.Display\n");
printf("6.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("Enter the number of elements to be entered : ");
scanf("%d",&n);

input(n);
break;
case 2:
insert();
break;
case 3:
printf("Enter the element to be searched : ");
scanf("%d", &item);
pos = search(item);
if(pos >= 1)
printf("%d found at position %d\n",item,pos);
else
printf("Element not found\n");
break;
case 4:
del();
break;
case 5:
display();
break;
case 6:
exit();
break;
default:
printf("Wrong choice\n");
} /*End of switch */
}/*End of while */
}/*End of main() */

input()
{
int i;
for(i = 0; i< n ; i++)
{
printf("Input value for element %d : ", i+1);
scanf("%d", &arr[i]);
}
}/*End of input()*/

int search(int item)
{
int i;
for(i=0; i < n; i++)
{
if(item == arr[i])
return(i+1);
}
return(0);  /* If element not found */
}/*End of search()*/

insert()
{
int temp,item,position;
if(n == MAX)
{
printf("List overflow\n");
return;
}
printf("Enter position for insertion : ");
scanf("%d", &position);
printf("Enter the value : ");
scanf("%d",&item);
if(position > n+1 )
{
printf("Enter position less than or equal to %d\n",n+1);
return;
}
if( position == n+1 )  /*Insertion at the end */
{
arr[n] = item;
n = n+1;
return;
}
/* Insertion in between */
temp=n-1;
while( temp >= position-1)
{
arr[temp+1] = arr[temp];  /* shifting right */
temp --;
}
arr[position-1] = item;
n = n +1 ;
}/*End of insert()*/

del()
{
int temp,position,item;
if(n == 0)
{
printf("List underflow\n");
return 0;
}
printf("Enter the element to be deleted : ");
scanf("%d",&item);
if(item==arr[n-1]) /*Deletion at the end*/
{
n = n-1;
return;
}
position=search(item);
if(position==0)
{
printf("Element not present in array\n");
return;
}
/*Deletion in between */
temp=position-1;
while(temp <= n-1)
{
arr[temp] = arr[temp+1];  /* Shifting left */
temp ++;
}
n = n - 1 ;
}/*End of del()*/

display()
{
int i;
if(n==0)
{
printf("List is empty\n");
return;
}
for(i = 0; i< n; i++)
printf("Value at position %d : %d\n", i+1, arr[i]);
}/*End of display()*/


WAP to implement the concept of linked list.


# include <stdio.h>
# include <malloc.h>

struct node
{
int info;
struct node *link;
}*start;

main()
{
int choice,n,m,position,i;
start=NULL;
while(1)
{
printf("1.Create List\n");
printf("2.Add at begining\n");
printf("3.Add after \n");
printf("4.Delete\n");
printf("5.Display\n");
printf("6.Count\n");
printf("7.Reverse\n");
printf("8.Search\n");
printf("9.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("How many nodes you want : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list(m);
}
break;
case 2:
printf("Enter the element : ");
scanf("%d",&m);
addatbeg(m);
break;
case 3:
printf("Enter the element : ");
scanf("%d",&m);
printf("Enter the position after which this element is inserted : ");
scanf("%d",&position);
addafter(m,position);
break;
case 4:
if(start==NULL)
{
printf("List is empty\n");
continue;
}
printf("Enter the element for deletion : ");
scanf("%d",&m);
del(m);
break;
case 5:
display();
break;
case 6:
count();
break;
case 7:
rev();
break;
case 8:
printf("Enter the element to be searched : ");
scanf("%d",&m);
search(m);
break;
case 9:
exit();
default:
printf("Wrong choice\n");
}/*End of switch */
}/*End of while */
}/*End of main()*/

create_list(int data)
{
struct node *q,*tmp;
tmp= malloc(sizeof(struct node));
tmp->info=data;
tmp->link=NULL;

if(start==NULL) /*If list is empty */
start=tmp;
else
{       /*Element inserted at the end */
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of create_list()*/

addatbeg(int data)
{
struct node *tmp;
tmp=malloc(sizeof(struct node));
tmp->info=data;
tmp->link=start;
start=tmp;
}/*End of addatbeg()*/

addafter(int data,int pos)
{
struct node *tmp,*q;
int i;
q=start;
for(i=0;i<pos-1;i++)
{
q=q->link;
if(q==NULL)
{
printf("There are less than %d elements",pos);
return;
}
}/*End of for*/

tmp=malloc(sizeof(struct node) );
tmp->link=q->link;
tmp->info=data;
q->link=tmp;
}/*End of addafter()*/

del(int data)
{
struct node *tmp,*q;
if(start->info == data)
{
tmp=start;
start=start->link;  /*First element deleted*/
free(tmp);
return;
}
q=start;
while(q->link->link != NULL)
{
if(q->link->info==data)     /*Element deleted in between*/
{
tmp=q->link;
q->link=tmp->link;
free(tmp);
return;
}
q=q->link;
}/*End of while */
if(q->link->info==data)    /*Last element deleted*/
{
tmp=q->link;
free(tmp);
q->link=NULL;
return;
}
printf("Element %d not found\n",data);
}/*End of del()*/

display()
{
struct node *q;
if(start == NULL)
{
printf("List is empty\n");
return;
}
q=start;
printf("List is :\n");
while(q!=NULL)
{
printf("%d ", q->info);
q=q->link;
}
printf("\n");
}/*End of display() */

count()
{
struct node *q=start;
int cnt=0;
while(q!=NULL)
{
q=q->link;
cnt++;
}
printf("Number of elements are %d\n",cnt);
}/*End of count() */

rev()
{
struct node *p1,*p2,*p3;
if(start->link==NULL)    /*only one element*/
return;
p1=start;
p2=p1->link;
p3=p2->link;
p1->link=NULL;
p2->link=p1;
while(p3!=NULL)
{
p1=p2;
p2=p3;
p3=p3->link;
p2->link=p1;
}
start=p2;
}/*End of rev()*/

search(int data)
{
struct node *ptr = start;
int pos = 1;
while(ptr!=NULL)
{
if(ptr->info==data)
{
printf("Item %d found at position %d\n",data,pos);
return;
}
ptr = ptr->link;
pos++;
}
if(ptr == NULL)
printf("Item %d not found in list\n",data);
}/*End of search()*/

WAP to implement the concept of queue.


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
void insert();
void del();
void dis();
void exo();
void show();
int queue[MAX],i,ch,ft=-1,rr=-1;
void main()
{

clrscr();
show();
getch();
}

void insert()
{
if(ft==MAX-1)
{
printf("\nQueue is full ");
}
else
{       rr=0;
ft++;
printf("\nEnter the element in queue ");
scanf("%d",&queue[ft]);
}
}
void del()
{
if(rr==-1)
{
printf("\nQueue if empty ");
}
else
{

printf("\nThe deleted element is %d",queue[rr]);
}
ft--;
rr++;

}
void dis()
{
if(rr==-1)
{
printf("\nQueue doesn't have any element in it ");
}
else
{
for(i=rr;i<=ft;i++)
{
printf("\n%d",queue[i]);
}
}
}
void exo()
{
exit (0);
}
void show()
{
do
{
printf("\nEnter your choice");
printf("\n1. Insert");
printf("\n2. Delete");
printf("\n3. Display");
printf("\n4. Exit ");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: del();
break;
case 3: dis();
break;
case 4: exo();
break;
default: printf("\nWrong Choice ");
break;
}
}while(ch!=4);
}

WAP to inplement the concept of stack with entring 5 elements, deleting & displaying the stack on the console screen.


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
void push();
void pop();
void display();
void exo();
int stack[MAX],i,top=-1,ch;
void main()
{

clrscr();
do
{
printf("\nEnter your choice");
printf("\n1. Push");
printf("\n2. Pop");
printf("\n3. Display");
printf("\n4. Exit ");
scanf("%d",&ch);
switch(ch)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exo();
break;
default: printf("\nWrong Choice ");
break;
}
}while(ch!=4);
getch();
}
void push()
{
if(top==MAX-1)
{
printf("\nStack is full ");
}

else
{
top++;
printf("\nEnter the element ");
scanf("%d",&stack[top]);

}
}
void pop()
{
if(top==-1)
{
printf("\nStack is empty ");
}
else
{
printf("\nThe deleted element is %d",stack[top]);

}
top--;
}
void display()
{
if(top==-1)
{
printf("\nStack doesn't have any element in it ");
}
else
{
printf("\n The stack elements are:-");
for(i=top;i>=0;i--)
{

printf("\n%d",stack[i]);

}
}
}
void exo()
{
exit (0);
}