}
void display()
{
int i;
printf(" top -->");
for(i=top;i>=0;i--)
printf("%d\n\t",s[i]);
}
OUTPUT:
Enter stack size: 3
1. Push
2. Pop
3. Exit
Enter your choice:1
Enter the element: 3
Top: 3
1. Push
2. Pop
3. Exit
Enter your choice:1
Enter the element: 5
Top: 5
3
1. Push
2. Pop
3. Exit
Enter your choice:1
Enter the element: 9
Top: 9 5 3
1. Push
2. Pop
3. Exit
Enter your choice: 1
Enter the element: 15
Stack is overflow
Top: 9 5 3
1. Push
2. Pop
3. Exit
Enter your choice: 3
Popped element is: 9
Top: 5 3
1. Push
2. Pop
3. Exit
Enter your choice: 2
Popped element is: 5
Top: 3
1. Push
68
2. Pop
3. Exit
Enter your choice: 2 Stack is underflow
1. Push
2. Pop
3. Exit
Enter your choice: 3
2. QUEUE USING ARRAYS
#include<stdio.h>
#include<conio.h>
#include<stdlib.h> void insertion(void); void deletion(void); void display(void);
int q[10],n,i,f,r;
int f=0,r=0; void main()
{
int op;
clrscr();
printf("ENTER THE SIZE OF QUEUE:"); scanf("%d",&n);
while(1)
{
printf("\n1.INSERTION\n2.DELETION\n3.DISPLAY\n4.EXIT\n");
printf("ENTER YOUR OPTION:");
scanf("%d",&op);
switch(op)
{
case 1:insertion(); break;
case 2:deletion(); break;
case 3:display(); break; default:exit(0);
} } }
void insertion()
{
if(r>=n)
printf("QUEUE IS OVER FLOW"); else
{
r=r+1;
printf("\nENTER AN ELEMENT TO INSERT:"); scanf("%d",&q[r]);
if(f==0)
f=1;
} }
void deletion()
{
if(f==0)
printf("THE QUEUE IS EMPTY"); else
{
printf("THE DELETING ELEMENT IS:%5d",q[f]); f=f+1;
if(f>r)
f=0,r=0;
} }
69
void display()
{
if(f==0)
printf("QUEUE IS EMPTY"); else
for(i=f;i<=r;i++)
printf("%5d",q[i]);
}
OUTPUT:
Enter the size of queue: 2
1. Insertion
2. Deletion
3. Display
4. Exit
Enter your option: 1
Enter an element to insert: q [1]:34
1. Insertion
2. Deletion
3. Display
4. Exit
Enter your option: 3 34
1. Insertion
2. Deletion
3. Display
4. Exit
Enter your option: 4
3: STACK APPLICATIONS
a) INFIX INTO POSTFIX
b) EVALUATION OF THE POSTFIX EXPRESSION
Program:(a)
#include<stdio.h>
#include<conio.h>
#define MAX 50
char stack[MAX];
int top=-1
void push(char); char pop();
int priority(char); void main()
{
char a[MAX],ch; int i;
clrscr();
printf("Enter an infix expression:\t"); gets(a);
printf("\the postfix expression for the given expression is:\t"); for(i=0;a[i]!='\0';i++)
{
ch=a[i];
if((ch>='a') && (ch<='z')) printf("%c",ch);
else if(ch=='(') push(ch); else if(ch==')')
{
70