-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
52 lines (45 loc) · 1.13 KB
/
stack.c
File metadata and controls
52 lines (45 loc) · 1.13 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
#include <stdio.h>
#define TAM 5
int top = -1;
void push(int *stack, int number);
char pop(int *stack);
void main(){
int stack[TAM];
int menu = 4, number;
while(menu != 0){
printf("\n (1). Push");
printf("\n (2). Pop");
printf("\n (0). Exit");
printf("\n\n Choose: ");
scanf("%d", &menu);
switch(menu){
case 1:
printf("\n Enter a number: ");
scanf("%d", &number);
push(stack, number);
break;
case 2:
pop(stack);
break;
}
}
}
void push(int *stack, int number){
if(top < TAM){
top++;
stack[top] = number;
printf("\n stack[%d]: %d", top, number);
}else{
printf("\n The stack is full");
printf("\n You can use the pop function");
}
}
char pop(int *stack){
if(top > -1){
printf("\nstack[%d] was removed", top);
return stack[--top];
}else{
printf("\n The stack is empty");
printf("\n You can use the push funcition");
}
}