-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
59 lines (49 loc) · 1.1 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
#include <stdio.h>
int myArray[5];
int top = -1;
void push(int item) {
if (top != 4) {
top++;
myArray[top] = item;
printf("%d Indexine Eleman eklendi\n", top);
} else {
printf("Stack Dolu\n");
}
}
void pop() {
if(top != -1) {
top--;
printf("Eleman silindi\n");
} else {
printf("Silinecek eleman yok\n");
}
}
int peek() {
return myArray[top];
}
void cleanStack() {
top = -1;
}
int main() {
while(!0) {
int select, numberItem;
printf("**************\n");
printf("-Push(1)\n-Pop(2)\n-Peek(3)\n-Clean-Stack(4)\n");
scanf("%d",&select);
switch(select) {
case 1:
printf("Stack'e eleman eklemek icin bir sayi gir\n");
scanf("%d",&numberItem);
push(numberItem);
break;
case 2:
pop();
break;
case 3:
printf("%d\n", peek());
break;
default:
printf("Lutfen gecerli bir secim yapiniz\n");
}
}
}