-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.C
More file actions
81 lines (79 loc) · 1.19 KB
/
stack.C
File metadata and controls
81 lines (79 loc) · 1.19 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<conio.h>
int t=-1,a[5];
void push(int);
void pop();
void peep(int);
void change(int,int);
void display();
int main()
{
int z,p;
char c;
printf("1.push\n2.pop\n3.peep\n4.change\n5.display\n6.exit\n");
for(;1;)
{
printf("\nenter your choice ");
c=getche();
switch (c)
{
case '1': printf("\nenter element..");
scanf("%d",&z);
push(z);
break;
case '2': pop();break;
case '3': printf("\nenter place from top..");
scanf("%d",&p);
peep(p);
break;
case '4': printf("\nenter place & new value..");
scanf("%d %d",&p,&z);
change(z,p);
break;
case '5': display();break;
case '6': return 0;break;
default: printf("\nwrong choice!!!");
}
}
}
void push(int z)
{
if(t<4)
{
t++;
a[t]=z;
}
else
printf("stack is full.\n");
}
void pop()
{
if(t>=0)
t--;
else
printf("\nno value in stack\n");
}
void peep(int p)
{
if((p-1)<=t)
printf("\n%d element from top is %d\n",p,a[t-p+1]);
else
printf("\nerror!!!!!\n");
}
void change(int z,int p)
{
if(t-p+1>=0&&p>0)
{
a[t-p+1]=z;
printf("\n%d element from top is %d\n",p,a[t-p+1]);
}
else
printf("\nnot possibl\n");
}
void display()
{
int x;
printf("\n");
for(x=0;x<=t;x++)
printf("%d\n",a[x]);
}