-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_even_odd.c
49 lines (45 loc) · 1015 Bytes
/
sort_even_odd.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
#include "lib/tools.h"
#include "lib/stack.h"
void sort(STACK **original, STACK **even, STACK **odd)
{
STACK *current = *original;
do
{
if (current -> value % 2 == 0)
push(even, current -> value);
else
push(odd, current -> value);
current = current -> next;
}
while (current);
}
int main(void)
{
STACK *myStack,
*even = NULL,
*odd = NULL;
FILE *output = openFile("output.txt", "w");
puts("Fill stack:");
myStack = create();
printf("\nOriginal stack: ");
printToFile(myStack, stdout);
sort(&myStack, &even, &odd);
if (even)
{
printf("List of even numbers: ");
printToFile(even, stdout);
printToFile(even, output);
}
if (odd)
{
printf("List of odd numbers: ");
printToFile(odd, stdout);
printToFile(odd, output);
}
fclose(output);
clear(myStack);
clear(even);
clear(odd);
system("pause");
return 0;
}