c program to implement a stack using an array

Solutions on MaxInterview for c program to implement a stack using an array by the best coders in the world

showing results for - "c program to implement a stack using an array"
Simon
10 Apr 2017
1#include<stdio.h>
2int stack[100],choice,n,top,x,i;
3void push(void);
4void pop(void);
5void display(void);
6int main()
7{
8    //clrscr();
9    top=-1;
10    printf("\n Enter the size of STACK[MAX=100]:");
11    scanf("%d",&n);
12    printf("\n\t STACK OPERATIONS USING ARRAY");
13    printf("\n\t--------------------------------");
14    printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY\n\t 4.EXIT");
15    do
16    {
17        printf("\n Enter the Choice:");
18        scanf("%d",&choice);
19        switch(choice)
20        {
21            case 1:
22            {
23                push();
24                break;
25            }
26            case 2:
27            {
28                pop();
29                break;
30            }
31            case 3:
32            {
33                display();
34                break;
35            }
36            case 4:
37            {
38                printf("\n\t EXIT POINT ");
39                break;
40            }
41            default:
42            {
43                printf ("\n\t Please Enter a Valid Choice(1/2/3/4)");
44            }
45                
46        }
47    }
48    while(choice!=4);
49    return 0;
50}
51void push()
52{
53    if(top>=n-1)
54    {
55        printf("\n\tSTACK is over flow");
56        
57    }
58    else
59    {
60        printf(" Enter a value to be pushed:");
61        scanf("%d",&x);
62        top++;
63        stack[top]=x;
64    }
65}
66void pop()
67{
68    if(top<=-1)
69    {
70        printf("\n\t Stack is under flow");
71    }
72    else
73    {
74        printf("\n\t The popped elements is %d",stack[top]);
75        top--;
76    }
77}
78void display()
79{
80    if(top>=0)
81    {
82        printf("\n The elements in STACK \n");
83        for(i=top; i>=0; i--)
84            printf("\n%d",stack[i]);
85        printf("\n Press Next Choice");
86    }
87    else
88    {
89        printf("\n The STACK is empty");
90    }
91   
92}
93
queries leading to this page
array based implementation of stack cc program array implementation of stackc program for implementation of stack using arrayc program for stack using arraysmall c program to implement stack using arraybasic operations of stack in cstack operations using array in cimplementing stack using array in cefficient implementation of stack using array in cc code to implement stack using 2arraystack c program using arrayuse of stack in cmplement stack in c using arrayhow to implement a stack in cstack in c arraystack in c using arrayimplement stack operation using array in c code in c to implement adt of stack using arrayarray stack cimplement stack in c using arraystack using array implementation in cstack in c arra6implementation of stack using arrays chow to implement stack using array in cc program to implement stack using arraydeclaring stack using an array c programmingstack opretions using array in coperations on a stack cimplement stack in c using array implement stack in cstack using array in chow to declare stack in cstack array implementation in cstack operations in c using arrayhow to declare an array in stack cimplementation of stack using array in c simple programstack implementation in c using arraybuild a program for stack using an array in cstack with array in c gfgoperations to implement in stack using cstacks using arrays in cstack in c arratstack array based implementation chow to implement stack in cimplement stack in c programstack implementation using array in cimplementation of stack using array in cefficient implementation of stack using array structure in chow to do array of structure with stack in cprogram using stack in cimplement stack using array in cstack code in c using arraystack array implementation cc program to implement a stack using an array