-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack03.c
More file actions
68 lines (66 loc) · 918 Bytes
/
Copy pathstack03.c
File metadata and controls
68 lines (66 loc) · 918 Bytes
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
//creating simple stack.
#include<stdio.h>
#define SIZE 10
int top=-1;
int stack[SIZE];
int isfull(){
if(top==SIZE-1)
return 1;
else
return 0;
}
int isempty(){
if(top==-1)
return 1;
else
return 0;
}
void push(int data){
if(isfull()){
printf("stack is full");
}
else{
top++;
stack[top]=data;}
}
void pop(){
int data;
if(isempty()){
printf("stack is empty");
}
else{
data=stack[top];
top--;
printf("popped element:%d\n",data);
}
}
void peek(){
if(isempty()){
printf("stack is empty");
}
else{
printf("\ntop element:%d\n",stack[top]);
}
}
void display(){
int i;
if(isempty()){
printf("stack is empty.");}
else{
printf("\nDisplaying all elements\n");
for(i=top;i>=0;i--)
{
printf("%d\t",stack[i]);}
}
}
int main(){
push(7);
push(2);
push(9);
push(11);
display();
peek();
pop();
display();
return 0;
}