refresh
This commit is contained in:
parent
780529c399
commit
e7a9c71f3d
Binary file not shown.
@ -57,12 +57,47 @@ void destroy_stack (struct stack* s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct stack* novystack = create_stack(STACK_SIZE);
|
struct stack* s = create_stack(STACK_SIZE);
|
||||||
push_stack(novystack, 3.14);
|
char input[101];
|
||||||
push_stack(novystack, 2.71);
|
while (scanf("%s", input)==1) {
|
||||||
float x = pop_stack(novystack);
|
char *end;
|
||||||
printf("Popped: %2.f\n", x);
|
float value = strtof(input, &end);
|
||||||
print_stack(novystack);
|
if (*end == '\0') {
|
||||||
destroy_stack(novystack);
|
push_stack(s, value);
|
||||||
|
print_stack(s);
|
||||||
|
} else if (strcmp(input, "+")==0 || strcmp(input, "-")==0 || strcmp(input, "*")==0 || strcmp(input, "/")==0) {
|
||||||
|
if (s->size < 2) {
|
||||||
|
printf("no input\n");
|
||||||
|
destroy_stack(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float b = pop_stack(s);
|
||||||
|
float a = pop_stack(s);
|
||||||
|
float result = 0;
|
||||||
|
|
||||||
|
if (strcmp(input, "+")==0) {
|
||||||
|
result = a+b;
|
||||||
|
}
|
||||||
|
if (strcmp(input, "-")==0) {
|
||||||
|
result = a - b;
|
||||||
|
}
|
||||||
|
if (strcmp(input, "*")==0) {
|
||||||
|
result = a * b;
|
||||||
|
}
|
||||||
|
if (strcmp(input, "/")==0) {
|
||||||
|
result = a/b;
|
||||||
|
}
|
||||||
|
push_stack(s);
|
||||||
|
print_stack(s);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("no input");
|
||||||
|
destroy_stack(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
destroy_stack(s);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user