You are on page 1of 4

new*

data structure new* new*


1 #include<stdio.h>
2 #include<conio.h>
3 int stack[100],choice,n,top,x,i;
4 void push(void);
5 void pop(void);
6 void display(void);
7 int main()
8 {
9 clrscr();
10 top=-1;
11 printf("\ n Enter the size of
STACK[MAX=100]:");
12 scanf("%d",&n);
13 printf("\ n\ t STACK OPERATIONS USING
ARRAY");
14 printf("\ n\ t------------------------");
15 printf("\ n\ t 1.PUSH\ n\ t 2.POP\ n\ t 3.
DISPLAY\ n\ t 4.EXIT");
16 do
17 {
18 printf("\ n Enter the Choice:");
19 scanf("%d",&choice);
20 switch (choice)
21 {
22 case 1:
23 {
24 push();
25 break;
26 }
27 case 2:
28 {
29 pop();
30 break;

Tab I { I } I : I ; I "
new*
data structure new* new*
31 }
32 case 3:
33 {
34 display();
35 break;
36 }
37 case 4:
38 {
39 printf("\n\t EXIT POINT ");
40 break;
41 }
42 default:
43 {
44 printf ("\n\t Please Enter a Valid Choice(1 /
2/3/4)");
45 }
46
47 }
48 }
49 while( choice!=4);
50 return O;
51 }
52 void push()
53 ~
54 if(top>=n-1)
55 {
56 printf("\n\tSTACK is over flow");
57 }
58 else
59 {
60 printf(" Enter a value of push :");
61 scanf("%d",&x);
62
.
top++;
- .. ►
Tab I { I } I : I ; I "
new*
data structure new* new*
6
64 }
65 ~
66 void pop()
67 {
68 if (top<=-1)
69 {
70 printf("\n\t stack is under flow");
71 }
72 else
73 {
74 printf("\n The pop elements is %d",
stack[top]);
75 top--;
76 }
77 }
78 void display()
79 {
80 if(top>=0)
81 {
82 printf(" The elements in stack \ n");
83 for(i=top; i>=0; i--)
84 {
85 printf("\n%d ",stack[i]);
86 }
87 printf("\n enter next choice");
88
89 }
90 else
91 {
92 printf("\n The STACK is empty");
93 }
94 }

Tab I { I } I : I ; I "
'i1.lll
Enter the size of STACK{MAX=100J:60

STACK OPERATIONS USING ARRAY

1. PUSH
2.POP
3.DISPLAY
4.EXIT
Enter the Choice:60

Please Enter a Valid Choice(1 / 2/3/4)


Enter the Choice:1
Enter a value of push:56

Enter the Choice:2

The pop elements is 56


Enter the Choice:3
The STACK is empty
Enter the Choice:4

EXIT POINT
[Program flnlshedJI

You might also like