0% found this document useful (0 votes)
6 views1 page

Stack

The document contains a C program that implements a stack data structure with basic operations: push, pop, and display. It features a menu-driven interface allowing users to interact with the stack until they choose to exit. The program includes error handling for stack overflow and underflow conditions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Stack

The document contains a C program that implements a stack data structure with basic operations: push, pop, and display. It features a menu-driven interface allowing users to interact with the stack until they choose to exit. The program includes error handling for stack overflow and underflow conditions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 #include <stdio.

h>
2 #include <stdlib.h>
3 #define size 10
4 int st[size] , top, count, item, i;
5
6 void push (){
7 if (top == size-1){
8 printf("************** OVERFLOW ************** ");
9 }
10 else {
11 printf("Enter the data: ");
12 scanf("%d ",item);
13 st[top] = item;
14 top = top + 1;
15 }
16 count++;
17
18 }
19
20 void pop(){
21 if (top == -1){
22 printf("************** UNDERFLOW **************** ");
23 }
24
25 else {
26 item = st[top];
27 top = top-1;
28 }
29 count--;
30 }
31
32 void display(){
33 printf ("STACK ELEMENTS ARE \n");
34 for (int i = count-1; i >= 0; i --){
35 printf("\n%d\n",st[i]);
36 }
37 }
38
39
40 void main(){
41 top = -1;
42 count = 0;
43 int ch = 0;
44
45 printf("******************* Menu Driven *************************");
46
47 while (ch!=7){
48 printf("\nChoose one option from the following list\n");
49 printf("------------------------------------------");
50 printf("\n [Link]\n [Link]\n [Link]\n [Link]\n");
51 printf ("Enter your choice : ");
52 scanf("%d",&ch);
53 switch(ch){
54 case 1 :
55 push();
56 break;
57
58 case 2 :
59 pop();
60 break;
61
62 case 3 :
63 display();
64 break;
65
66 case 4 :
67 printf("SUCCESSFULLY EXIT ......");
68 exit(0);
69 break;
70
71 default :
72 printf("Please enter valid choice .....\n");
73 }
74 }
75 }
76

You might also like