-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlgoritmaQuiz1.c
89 lines (79 loc) · 1.39 KB
/
AlgoritmaQuiz1.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//tek bir dizi ile iki ayrı stack tut.
#define kapasite 50
#include <stdio.h>
char stack[kapasite] = {' '};
short top = 0, top2 = kapasite - 1;
void push(short nereye, char neyi)
{
if (top == top2)
{
printf("Stack overflow!\n");
}
else
{
if (nereye == 0)
stack[top++] = neyi;
else
stack[top2--] = neyi;
}
}
void pop(short neresi)
{
if (neresi == 0)
{
if (top == 0)
{
printf("There is nothing to pop it!\n");
}
else
{
top--;
printf("Stack1 is popped\n");
}
}
else
{
if (top2 == kapasite - 1)
{
printf("There is nothing to pop it!\n");
}
else
{
top2++;
printf("Stack2 is popped\n");
}
}
}
void display(short neresi)
{
short i;
if (neresi == 0)
{
printf("Stack 1:\n");
for (i = top - 1; i >= 0; i--)
printf("%c", stack[i]);
printf("\n");
}
else
{
printf("Stack 2:\n");
for (i = top2 + 1; i < kapasite; i++)
printf("%c", stack[i]);
printf("\n");
}
}
int main()
{
push(0, 'a');
push(0, 'b');
push(1, 'c');
push(1, 'd');
push(0, 'e');
display(0);
display(1);
pop(0);
pop(1);
display(0);
display(1);
return 0;
}