-
Notifications
You must be signed in to change notification settings - Fork 2
/
stack.c
65 lines (61 loc) · 1.13 KB
/
stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#define MAX 3
void push(int[]);
void print(int[]);
int top=-1;
int main()
{
int choice;
int data[MAX];
do
{
system("cls");
printf("\n\
1.Push \n\
2.Print stack \n\
3.Exit\n\
");
printf("enter ur choice :");
scanf("%d",&choice);
switch (choice)
{
case 1:
push(data);
break;
case 2:
print(data);
break;
case 3:
exit(0);
break;
default:printf("invalid operation!!!\n");
break;
}
printf("\nenter any key to continue.....");
getch();
} while (1);
return 0;
}
void push(int arr[])
{
if (top>=MAX-1)
{
printf("Overflow !!\n");
}
else
{
printf("enter the element :");
scanf("%d",&arr[++top]);
printf("item added succesfully!! \n");
}
}
void print(int arr[])
{
printf(" Total elements =%d \n",top+1);
for (int i = top; i >= 0; i--)
{
printf(" %d ",arr[i]);
}
}