-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevenness.c
50 lines (46 loc) · 1001 Bytes
/
evenness.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
#include "lib/tools.h"
#include "lib/stack.h"
int getStackParity(STACK **head)
{
bool even = false,
odd = false;
STACK *current = *head;
do
{
if (current -> value % 2 == 0)
even = true;
else
odd = true;
current = current -> next;
} while (current);
if (even && odd)
return 2;
if (odd)
return 1;
return 0;
}
int main(void)
{
STACK *myStack;
FILE *output = openFile("output.txt", "w");
puts("Fill stack:");
myStack = create();
printf("\nOriginal stack: ");
printToFile(myStack, stdout);
printToFile(myStack, output);
switch (getStackParity(&myStack))
{
case 0:
puts("The stack is even.");
break;
case 1:
puts("The stack is odd.");
break;
default:
puts("The stack is neither even nor odd.");
}
fclose(output);
clear(myStack);
system("pause");
return 0;
}