-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidatorApp1.c
More file actions
39 lines (35 loc) · 872 Bytes
/
Copy pathvalidatorApp1.c
File metadata and controls
39 lines (35 loc) · 872 Bytes
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
#include<stdio.h>
#include"StackADT.h"
#include"validator.h"
bool pushWithValidate(stackADT stack, int value, Validator *pValidator)
{
if (pValidator && !pValidator -> validate(pValidator, value)){
return false;
}
return push(stack, value);
}
int main(int argc, char *argv[])
{
stackADT stack;
int temp;
stack = newStack();
RangeValidator rangeValidator = newRangeValidator(0, 9);
for (int i = 0; i < 16; i++){
pushWithValidate(stack, i, &rangeValidator.isa);
}
while(!stackIsEmpty(stack)){
pop(stack, &temp);
printf("%d ", temp);
}
printf("\n");
OddEvenValidator oddEvenValidator = newOddEvenValidator(true);
for (int i = 0; i < 16; i ++){
pushWithValidate(stack, i, &oddEvenValidator.isa);
}
while (!stackIsEmpty(stack)) {
pop(stack, &temp);
printf("%d ", temp);
}
freeStack(stack);
return 0;
}