From 124fd714d78e088cd64e90a525d4a0d33d5894f2 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Tue, 16 Mar 2021 08:34:33 +0800 Subject: [PATCH] week 3 make main.c --- week3/Makefile | 2 +- week3/main.c | 27 +++++++++++++++++++++++++++ week3/stack.c | 25 ------------------------- 3 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 week3/main.c diff --git a/week3/Makefile b/week3/Makefile index 39f1b26..97a1b16 100644 --- a/week3/Makefile +++ b/week3/Makefile @@ -1,2 +1,2 @@ stack:stack.c stack.h - gcc stack.c stack.h -Wall -o stack + gcc main.c stack.c stack.h -Wall -o stack diff --git a/week3/main.c b/week3/main.c new file mode 100644 index 0000000..48f126c --- /dev/null +++ b/week3/main.c @@ -0,0 +1,27 @@ +#include +#include "stack.h" + +/* test function */ +int main() { + Stack stack; + double val; + CreateStack(&stack, 5); + Push(&stack, 5.0); + Push(&stack, 6.5); + Push(&stack, -3.0); + Push(&stack, -8.0); + DisplayStack(&stack); + if (Top(&stack, &val)) { + printf("Top: %f\n", val); + } + Pop(&stack, &val); + if (Top(&stack, &val)) { + printf("Top: %f\n", val); + } + while(!IsEmpty(&stack)) { + Pop(&stack, &val); + } + DisplayStack(&stack); + DestroyStack(&stack); + return 0; +} diff --git a/week3/stack.c b/week3/stack.c index 96bba9f..1c5d66d 100644 --- a/week3/stack.c +++ b/week3/stack.c @@ -13,31 +13,6 @@ #include "stack.h" -/* test function */ -int main() { - Stack stack; - double val; - CreateStack(&stack, 5); - Push(&stack, 5.0); - Push(&stack, 6.5); - Push(&stack, -3.0); - Push(&stack, -8.0); - DisplayStack(&stack); - if (Top(&stack, &val)) { - printf("Top: %f\n", val); - } - Pop(&stack, &val); - if (Top(&stack, &val)) { - printf("Top: %f\n", val); - } - while(!IsEmpty(&stack)) { - Pop(&stack, &val); - } - DisplayStack(&stack); - DestroyStack(&stack); - return 0; -} - bool CreateStack(Stack *stack, int size) { /* check */ assert(size > 0);