DATASTRUCTURESLIP
DATASTRUCTURESLIP
DATASTRUCTURESLIP
Q1.Implement a list library (doublylist.h) for a doubly linked list of integers with the create, display
operations. Write a menu driven program to call these operations. [10]
SOLUTION:
HEADER FILE-
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
};
void create()
int n,i;
scanf("%d",&n);
scanf("%d",&f->data);
f->prev=NULL;
s=f;
for(i=1;i<n;i++)
scanf("%d",&s->data);
}
s->next= NULL;
void display()
=NULL;s=s->next)
MAIN PROGRAM-
#include <stdio.h>
#include "doublylist.h"
int main()
int ch;
do
printf("\n1.create\n2.display\n0.exit");
scanf("%d",&ch);
switch (ch)
case 1: create();
break;
case 2: display();
break;
case 0: break;
}while(ch!=0);
}
Q2. Write a program that sorts the elements of linked list using any of sorting technique. [20]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
struct node
{ int data;
};
void create()
int i,n;
scanf("%d",&n);
scanf("%d",&f->data);
s=f;
for(i=1;i<n;i++)
scanf("%d",&s->data);
s->next=NULL;
void display()
printf("\t %d ->",s->data);
void sort()
int temp;
for(p=f;p!=NULL;p=p->next)
for(q=p->next;q!=NULL;q=q->next)
temp = p->data;
p->data = q->data;
q->data = temp;
int main()
create();
display();
sort();
display();
}
SLIP 2
Q1. Implement a list library (singlylist.h) for a singly linked list of integer with the operations create,
display. Write a menu driven program to call these operations [10]
SOLUTION:
HEADER FILE-
struct node
int data;
};
void create()
int n,i;
scanf("%d",&n);
scanf("%d",&f->data);
s=f;
for(i=1;i<n;i++)
scanf("%d",&s->data);
s->next= NULL;
}
void display()
=NULL;s=s->next)
printf("%d ->",s->data);
MAIN PROGRAM-
#include <stdio.h>
#include "singlylist.h"
int main()
{ int ch;
do{
printf("\n1.create\n2.display\n3.exit");
scanf("%d",&ch);
switch (ch)
case 1: create();
break;
case 2: display();
break;
case 3: break;
}while(ch!=3);
Q2. Write a program that copies the contents of one stack into another. Use stack library to perform
basic stack operations. The order of two stacks must be identical.(Hint: Use a temporary stack to
preserve the order). [20]
SOLUTION:
#include <stdio.h>
char s[20];
int top;
void init()
top=-1;
int isempty(){
if(top==-1)
return 1;
else
return 0;
int isfull()
if(top==19)
return 1;
else
return 0;
if(isfull()==1)
printf("stack is full");
else
top++;
s[top]=ch;
}
char pop()
char ch;
if(isempty()==1)
printf("stack is empty");
else
ch=s[top];
top--;
return ch;
int main()
int i,k=0;
char temp[20];
init();
char str[20];
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
push(str[i]);
while(!isempty())
temp[k]=pop();
k++;
}
temp[k]='\0';
for(i=0;temp[i]!='\0';i++)
push(temp[i]);
while(!isempty())
printf("%c",pop());
}
SLIP 3
Q1. Sort a random array of n integers (accept the value of n from user) in ascending order by using
insertion sort algorithm. [10]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
int main()
int a[10],i,j,n,key;
scanf("%d",&n);
a[i]=rand()%100;
for(i=0;i<n;i++)
printf("%d ",a[i]);
key = a[i];
a[j+1]=a[j];
else
break;
a[j+1]=key;
printf("%d ",a[i]);
SOLUTION:
#include<stdio.h>
#include<string.h>
char s[20];
int top;
void init()
top=-1;
int isempty()
{ if(top==-1)
return 1;
else return 0;
int isfull()
{ if(top==19)
return 1;
else
return 0;
if(isfull()==1) printf("\
{ top++;
s[top]=data;
char pop()
{ char data;
if(isempty()==1) printf("\
{ data=s[top];
top--;
return data;
{ int i,op1,op2,val;
for(i=0;str[i]!='\0';i++)
{ switch(str[i])
op1=pop();
push(op1+op2); break;
op1=pop();
push(op1-op2); break;
op1=pop();
push(op1*op2); break;
op1=pop();
push(op1/op2); break;
push(val);
int main()
{ char str[20];
scanf("%s",str);
postfix_eval(str);
}
SLIP 5
Q1. Create a random array of n integers. Accept a value x from user and use linear search algorithm
to check whether the number is present in the array or not and output the position if the number is
present. [10]
SOLUTION:
#include<stdio.h>
{ int i,p,cnt=0;
for(i=0;i<n;i++)
if(a[i]==sr)
{ p=i;
cnt++;
break;
if(cnt>=1)
int main()
int n,i,sr,a[10];
for(i=0;i<n;i++)
printf("enter values");
scanf("%d",&a[i]);
scanf("%d",&sr);
linearsearch(a,n,sr);
Q2. Implement a priority queue library (PriorityQ.h) of integers using a static implementation of the
queue and implement the below two operations.
SOLUTION:
HEADER FILE-
#include<stdio.h>
int Q[20];
int f,R;
void init()
f=R=-1;
int isempty()
if(f==R)
return 1;
else
return 0;
}
int isfull()
if(R==19)
return 1;
else return 0;
{ int i;
if(isfull()==1)
else
for(i=R;i>f;i--)
{ if(no<Q[i])
Q[i+1]=Q[i];
else
break;
Q[i+1]=no;
R++;
int Delete()
{ int no;
if(isempty()==1)
else
{ f+
+;
no=Q[f];
}
return no;
void display()
int i;
for(i=f+1;i<=R;i++)
{ printf("%d ",Q[i]);
MAIN PROGRAM-
#include<stdio.h>
#include "PriorityQ.h"
int main()
int n,ch;
init();
do
scanf("%d",&ch);
switch(ch)
Add(n);
break;
break;
case 3:display();
break;
case 0:break;
}while(ch!=0);
SLIP 6
Q1. Sort a random array of n integers (accept the value of n from user) in ascending order by using
selection sort algorithm. [10]
SOLUTION:
#include<stdio.h>
#define size 5
void main()
int arr[size],i,j,temp,min;
for(i=0;i<=size-1;i++)
scanf("%d",&arr[i]);
for(i=0;i<=size-1;i++)
min=i;
for(j=0;j<=size-1;j++)
if(arr[min]<arr[j])
{
temp=arr[j];
arr[j]=arr[min];
arr[min]=temp;
for(i=0;i<=size-1;i++)
printf("\n %d",arr[i]);
Q2. Implement a queue library (dyqueue.h) of integers using a dynamic (linked list) implementation
of the queue and implement init, enqueue, dequeue, isempty, peek operations. [20]
SOLUTION:
HEADER FILE-
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
};
void init()
f=NULL;
r=NULL;
}
int isempty()
if(f==NULL)
return 1;
else
return 0;
void enqueue()
struct node*nw;
int n;
nw->data=n;
nw->next=NULL;
if(f==NULL)
f=nw;
r=nw;
else
r->next=nw;
r=r->next;
int dequeue()
int n;
if(isempty()==1)
printf("queue is empty");
else
temp=f;
f=f->next;
n=temp->data;
free(temp);
int peek()
return f->data;
MAIN PORGRAM-
#include<stdio.h>
#include"dyqueue.h"
int main()
int ch,no;
init();
do
scanf("%d",&ch);
switch(ch)
scanf("%d",&no);
enqueue(no);
break;
case 2:if(isempty()==1)
break;
case 0:break;
}while(ch!=0);
SLIP 7
Q1. Sort a random array of n integers (accept the value of n from user) in ascending order by using
quick sort algorithm. [10]
SOLUTION:
#include<stdio.h>
int main()
int n,array[1000],c,d,t;
scanf("%d",&n);
printf("enter %d integers",n);
for(c=0;c<n;c++)
scanf("%d",&array[c]);
for(c=1;c<=n-1;c++)
{
d=c;
while(d>0&&array[d-1]>array[d])
t=array[d];
array[d]=array[d-1];
array[d-1]=t;
d--;
for(c=0;c<=n-1;c++)
printf("%d\n",array[c]);
return 0;
Q2. Write a program that checks whether a string of characters is palindrome or not. The function
should use a stack library (cststack.h) of stack of characters using a static implementation of the
stack. [20]
SOLUTION:
HEADER FILE-
int top,stack[max];
void push(char x)
if(top == max-1){
printf("stack overflow");
} else { stack[+
+top]=x;
}
void pop()
printf("%c",stack[top--]);
MAIN PROGRAM-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cststack.h"
void main()
int i,front;
char s[MAX], b;
scanf("%s", s);
b = s[i];
push(b);
if (stack[top] == stack[front])
pop();
front++;
else
{
break;
if ((strlen(s) / 2) == front)
front = 0;
top = -1;
SLIP 8
Q1. Implement a list library (singlylist.h) for a singly linked list of integer With the operations create,
delete specific element and display. Write a menu driven program to call these operations
[10]
SOLUTION:
HEADER FILE-
void create();
void display();
void deletell();
struct node
int info;
}*start=NULL;
void create()
int data;
printf("enter element");
scanf("%d",&data);
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
if(start=NULL)
start=tmp;
else
q=start;
while(q->next!=NULL)
q=q->next;
q->next=tmp;
void display()
if(start==NULL)
printf("list is empty");
else
printf("\n****elements in list*****\n");
q=start;
while(q!=NULL)
printf("%d\t",q->info);
q=q->next;
void deletell()
{
int data;
scanf("%d",&data);
if(start->info==data)
tmp=start;
start=start->next;
free(tmp);
return;
q=start;
while(q->next->next!=NULL)
if(q->next=tmp->next)
tmp=q->next;
q- >next=tmp->next;
free(tmp);
return;
q=q->next;
if(q->next->info==data)
tmp=q->next;
q->next=NULL;
free(tmp);
return;
}
printf("elemnet not found");
MAIN PROGRAM-
#include<stdio.h>
#include<stdlib.h>
#include"singlylist.h"
void main()
int n;
scanf("%d",&n);
while(1)
switch(n)
case 1: create();
break;
case 2: display();
break;
case 3: deletell();
display();
break;
case 4: exit(0);
Q2. Write a C program to check whether the contents of two stacks are identical. Use stack library to
perform basic stack operations. Neither stack should be changed. [20]
SOLUTION:
#include <stdio.h>
char s[20];
int top;
void init()
top=-1;
int isempty(){
if(top==-1)
return 1;
else
return 0;
int isfull()
if(top==19)
return 1;
else
return 0;
if(isfull()==1)
printf("stack is full");
else
top++;
s[top]=ch;
char pop()
{
char ch;
if(isempty()==1)
printf("stack is empty");
else
ch=s[top];
top--;
return ch;
int main()
int i,k=0;
char temp[20];
init();
char str[20];
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
push(str[i]);
while(!isempty())
temp[k]=pop();
k++;
temp[k]='\0';
printf("second string :");
for(i=0;temp[i]!='\0';i++)
push(temp[i]);
while(!isempty())
printf("%c",pop());
for(i=0;temp[i]!='\0';i++)
push(temp[i]);
while(!isempty())
printf("%c",pop());
}
SLIP 9
Q1. Write a program to convert an infix expression of the form (a*(b+c)*((da)/b)) into its equivalent
postfix notation. Consider usual precedence’s of operators. Use stack library of stack of characters
using static implementation. [10]
SOLUTION:
#include<stdio.h>
#include<ctype.h>
char stack[100];
void push(char x)
stack[++top] = x;
}
char pop()
if(top == -1)
return -1;
else
return stack[top--];
int priority(char x)
if(x == '(')
return 0;
return 1;
return 2;
return 0;
int main()
char exp[100];
char *e, x;
scanf("%s",exp);
printf("\n");
e = exp;
while(*e != '\0')
if(isalnum(*e))
printf("%c ",*e);
push(*e);
else if(*e == ')')
else
printf("%c ",pop());
push(*e);
} e+
+;
while(top != -1)
printf("%c ",pop());
}return 0;
Q2 Read the data from the ‘employee.txt’ file and sort on age using Counting sort and Quick sort and
write the sorted data to another file 'sortedemponage.txt'. [20]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct employee
char name[20];
int age;
}emp[10];
int i=0;
FILE *fp;
if((fp=fopen("emp.txt","r"))!=NULL)
while(!feof(fp))
fscanf(fp,"%s%d",a[i].name,&a[i].age); i++;
return i-1;
{ int i,j;
if(lb<ub)
i=lb+1;
key=a[lb];
j=ub;
while(i<=j)
i++;
j--;
if(i<j)
temp=a[i];
a[i]=a[j];
a[j]=temp;
temp=a[j];
a[j]=a[lb];
a[lb]=temp;
quicksort(a,lb,j-1);
quicksort(a,j+1,ub);
int i=0;
FILE *fp;
if((fp=fopen("sortedemp_quick_age.txt","w"))!=NULL) {
for(i=0;i<n;i++)
{ fprintf(fp,"%s %d\n",a[i].name,a[i].age); }
void main()
{ int n;
n=readFile(emp);
if(n==-1)
else
quicksort(emp,0,n-1);
writeFile(emp,n);
SLIP 10
Q1. Implement a linear queue library (st_queue.h) of integers using a static implementation of the
queue and implementing the init(Q), add(Q) and peek(Q) operations. Write a program that includes
queue library and calls different queue operations [10]
SOLUTION:
HEADER FILE-
#include<stdio.h>
int Q[20];
int f,R;
void init()
{ f=R=-1;
int isempty()
if(f==R)
return 1;
else
return 0;
int isfull()
if(R==19)
return 1;
else return 0;
if(isfull()==1)
else
{ R+
+;
Q[R]=no;
int Delete()
{ int no;
if(isempty()==1)
else
{
f++;
no=Q[f];
return no;
void display()
int i;
for(i=f+1;i<=R;i++)
{ printf("%d ",Q[i]);
MAIN PROGRAM-
#include<stdio.h>
#include "st_queue.h"
void main()
{ int n,ch;
init();
do
scanf("%d",&ch);
switch(ch)
Add(n);
break;
break;
case 3:display();
break;
}while(ch!=0);
Q2. Read the data from the file “employee.txt” and sort on names in alphabetical order (use strcmp)
using bubble sort and selection sort. [20]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct employee
char name[20];
int age;
}emp[10];
int i=0;
FILE*fp;
if((fp=fopen("empl.txt","r"))!=NULL)
while(!feof(fp))
return i-1;
}
void writefile(struct employee a[],int n)
int i;
FILE *fp;
if((fp=fopen("bsort.txt","w"))!=NULL)
for(i=0;i<n;i++)
int i,j;
for(i=0;i<n-1;i++)
for(j=0;j<n-1;j++)
if(strcmp(a[j].name,a[j+1].name)>0) {
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
void main()
int n;
n=readfile(emp);
if(n==-1)
else
bubblesort(emp,n);
writefile(emp,n);
printf("File is found");
SLIP 11
Q1. Read the data from file 'cities.txt' containing names of cities and their STD codes. Accept a name
of the city from user and use sentinel linear search algorithm to check whether the name is present
in the file and output the STD code, otherwise output “city not in the list”. [10]
SOLUTION:’
#include<stdio.h>
void sentinelsearch(int a[10],int n,int sr)
int i,cnt=0;
a[n]=sr;
while(sr!=a[i])
{ i++;
if(i<n)
int main()
int n,i,sr,a[10];
scanf("%d",&n);
for(i=0;i<n;i++)
printf("enter values");
scanf("%d",&a[i]);
scanf("%d",&sr);
sentinelsearch(a,n,sr);
Q2. Implement a priority queue library (PriorityQ.h) of integers using a static implementation of the
queue and implementing the below two operations. Write a driver program that includes queue
library and calls different queue operations.
SOLUTION:
HEADER FILE-
#include<stdio.h>
int Q[20];
int f,R;
void init()
f=R=-1;
int isempty()
if(f==R)
return 1;
else
return 0;
int isfull()
if(R==19)
return 1;
else return 0;
{ int i;
if(isfull()==1)
else
for(i=R;i>f;i--)
{ if(no<Q[i])
Q[i+1]=Q[i];
else
break;
Q[i+1]=no;
R++;
int Delete()
{ int no;
if(isempty()==1)
else
{ f+
+;
no=Q[f];
return no;
void display()
int i;
for(i=f+1;i<=R;i++)
{ printf("%d ",Q[i]);
MAIN PROGRAM-
#include<stdio.h>
#include "PriorityQ.h"
int main()
int n,ch;
init();
do
scanf("%d",&ch);
switch(ch)
Add(n);
break;
break;
case 3:display();
break;
case 0:break;
}while(ch!=0);
SLIP 12
Q1. Read the data from file 'cities.txt' containing names of cities and their STD codes. Accept a name
of the city from user and use linear search algorithm to check whether the name is present in the file
and output the STD code, otherwise output “city not in the list”. [10]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct city
char name[20];
int code;
}ct[10];
int i=0;
FILE *fp;
if((fp=fopen("city.txt","r"))!=NULL)
while(!feof(fp))
fscanf(fp,"%s%d",a[i].name,&a[i].code); i++;
return i-1;
{ int i,p,cnt=0;
for(i=0;i<n;i++)
if(strcmp(a[i].name,sr)==0)
{ p=i;
cnt++;
break;
}
}
if(cnt>=1)
void main()
{ int n;
char sr[20];
n=readFile(ct);
if(n==-1)
else
scanf("%s",sr);
linearsearch(ct,n,sr);
Q2.Implement a circular queue library (cir_queue.h) of integers using a dynamic (circular linked list)
implementation of the queue and implementing init(Q), AddQueue(Q) and DeleteQueue(Q)
operations. Write a menu driven program that includes queue library and calls different queue
operations. [20]
SOLUTION:
HEADER FILE-
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node *next;
};
void init()
r=NULL;
int isempty()
if(r==NULL)
return 1;
else
return 0;
void Add(int n)
nw->data=n;
if(r==NULL)
r=nw;
r- >next=r;
else
nw->next=r->next;
r->next=nw;
r=r->next;
}
int Delete()
int no;
temp=r->next;
if(r==temp->next)
{ r=NULL;
else
r- >next=temp->next;
no=temp->data;
free(temp);
return (no);
int peek()
return r->next->data;
MAIN PROGRAM-
#include<stdio.h>
#include "dyqueue.h"
int main()
{ int ch,no;
init();
do
scanf("%d",&ch);
switch(ch)
Add(no);
break;
case 2:if(isempty()==1)
break; }
case 0:break;
default:printf("Invalid choice"); }
}while(ch!=0);
SLIP 13
Q1. Implement a stack library (ststack.h) of integers using a static implementation of the stack and
implementing the operations like init(S), S=push(S) and S=pop(S). Write a driver program that
includes stack library and calls different stack operations. [10]
SOLUTION:
HEADER FILE-
#include<stdio.h>
char s[20];
int top;
void init()
top=-1;
int isempty()
{ if(top==-1)
return 1;
else return 0;
int isfull()
{ if(top==19)
return 1;
else
return 0;
if(isfull()==1) printf("\
{ top++;
s[top]=data;
}
char pop()
{ char data;
if(isempty()==1) printf("\
{ data=s[top];
top--;
return data;
int peek()
{ return s[top];
MAIN PROGRAM-
#include<stdio.h>
#include<stdlib.h>
#include"sstack.h"
int main()
int n,i=0,ch;
init();
do
printf("\n1.push \n2.pop \n3.chech stack is empty or not \n4.chech stack is full or not \n5.Peek
\n0.exit");
scanf("%d",&ch);
switch(ch)
push(n);
break;
case 3:if(isempty()==1)
printf("stack is empty");
else
break;
case 4:if(isfull()==1)
printf("stack is full");
else
break;
case 0: break;
}while(ch!=0);
Q2. Write a program that sorts the elements of linked list using bubble sort technique. [20]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
struct node
{ int data;
};
struct node *f;
void create()
int i,n;
scanf("%d",&n);
scanf("%d",&f->data);
s=f;
for(i=1;i<n;i++)
scanf("%d",&s->data);
s->next=NULL;
void display()
=NULL;s=s->next)
{ printf("\t %d ->",s->data);
void sort()
int temp;
for(p=f;p!=NULL;p=p->next)
{
for(q=p->next;q!=NULL;q=q->next)
{ temp = p->data;
p->data = q->data;
q->data = temp;
int main()
create();
display();
sort();
display();
}
SLIP 15
Q1. Sort a random array of n integers (accept the value of n from user) in ascending order by using
selection sort algorithm. [10]
SOLUTION:
#include<stdio.h>
#include<stdlib.h>
int main()
int i,a[10],n,min,pos,j,temp;
scanf("%d",&n);
for(i=0;i<n;i++)
a[i]=rand()%100;
for(i=0;i<n;i++)
printf("%d ",a[i]);
for(j=0;j<n-1;j++)
min=a[j];
pos=j;for(i=j+1;i<n;i++)
if(a[i]<=min)
min=a[i];
pos=i;
}
temp=a[j];
a[j]=min;
a[pos]=temp;
for(i=0;i<n;i++)
printf("%d ",a[i]);
Q2. Implement a linear queue library (dyqueue.h) of integers using a dynamic (circular linked list)
implementation of the queue and implementing the five queue operations (init(Q), AddQueue(Q, x),
X=DeleteQueue(Q), X=peek(Q), isEmpty(Q)). [20] Write a
program to reverse the elements of a queue using queue library.
SOLUTION:
HEADER FILE-
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
};
void init()
r=NULL;
}
int isempty()
if(r==NULL)
return 1;
else
return 0;
void Add(int n)
nw->data=n;
if(r==NULL)
r=nw;
r->next=r;
else
nw->next=r->next;
r->next=nw;
r=r->next;
int Delete()
int no;
temp=r->next;
if(r==temp->next)
{ r=NULL;
}
else
r- >next=temp->next;
no=temp->data;
free(temp);
return (no);
int peek()
return r->next->data;
MAIN PROGRAM-
#include<stdio.h>
#include "dyqueue.h"
int main()
{ int ch,no;
init();
do
printf("Enter choice");
scanf("%d",&ch);
switch(ch)
Add(no);
break;
case 2:if(isempty()==1)
break; }
case 0:break;
default:printf("Invalid choice"); }
}while(ch!=0);
}
SLIP 17
Q1 Implement a list library (singlylist.h) for a singly linked list. Create a linked list, reverse it and
display reversed linked list. [10]
SOLUTION:
HEADER FILE-
#include <stdio.h>
#include <stdlib.h>
struct node
int data;
};
void create()
int n,i;
scanf("%d",&n);
printf("Enter data");
scanf("%d",&f->data);
s=f;
for(i=1;i<n;i++)
{
s- >next=(struct node *)malloc(sizeof(struct node)); s=s->next;
printf("Enter data");
scanf("%d",&s->data);
s->next=NULL;
void display()
=NULL;s=s->next)
printf("%d ->",s->data);
void reverse()
int cnt=0,i;
for(s=f;s!=NULL;s=s->next)
cnt++;
while(cnt>0)
for(i=1,s=f;i<cnt;i++)
s=s->next;
printf("%d ->",s->data);
cnt--;
}
}
MAIN PROGRAM-
#include<stdio.h>
#include"singlylist.h"
int main()
create();
display();
reverse();
Q2 Write a program that copies the contents of one stack into another. Use stack library to perform
basic stack operations. The order of two stacks must be identical.(Hint: Use a temporary stack to
preserve the order). [20]
SOLUTION:
#include <stdio.h>
char s[20];
int top;
void init()
top=-1;
int isempty(){
if(top==-1)
return 1;
else
return 0;
int isfull()
if(top==19)
return 1;
else
return 0;
if(isfull()==1)
printf("stack is full");
else
top++;
s[top]=ch;
char pop()
char ch;
if(isempty()==1)
printf("stack is empty");
else
ch=s[top];
top--;
return ch;
int main()
int i,k=0;
char temp[20];
init();
char str[20];
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
push(str[i]);
while(!isempty())
temp[k]=pop();
k++;
temp[k]='\0';
for(i=0;temp[i]!='\0';i++)
push(temp[i]);
while(!isempty())
printf("%c",pop());