-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackUse.c
More file actions
71 lines (64 loc) · 1.04 KB
/
Copy pathStackUse.c
File metadata and controls
71 lines (64 loc) · 1.04 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
#include <stdio.h>
int Index = -1;
int size;
int push(int value, int *arr)
{
if (size - 1 == Index)
{
return 0;
}
else
{
Index++;
arr[Index] = value;
return 1;
}
}
int pop(int *arr)
{
if (Index == -1)
{
return -1;
}
else
{
Index--;
return arr[Index + 1];
}
}
int main(void)
{
scanf("%d", &size);
int arr[size];
int Main[size];
int i;
for (i = 0; i < size; i++)
{
scanf(" %d", &Main[i]);
}
for (i = size - 1; i >= 0; i--)
{
int j;
for (j = i + 1; j < size - 1; j++)
{
if (Main[i] < Main[j])
{
break;
}
}
if (j == size)
{
push(-1, arr);
}
else
{
push(Main[j], arr);
}
}
for (i = Index; i >= 0; i--)
{
printf("%d ", pop(arr));
}
printf("\n");
return 0;
}