From b70153e861af2b1c51d07926b7829ba0a3264a6b Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sun, 10 Dec 2017 09:07:59 +0800 Subject: chap4 for data structure --- .../data_structures/chapter_3/stack_array.c | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'Computer_Science/data_structures/chapter_3/stack_array.c') diff --git a/Computer_Science/data_structures/chapter_3/stack_array.c b/Computer_Science/data_structures/chapter_3/stack_array.c index 4c23334..57a7fad 100644 --- a/Computer_Science/data_structures/chapter_3/stack_array.c +++ b/Computer_Science/data_structures/chapter_3/stack_array.c @@ -3,15 +3,15 @@ #include "stack_array.h" -#define EMPTY_TOS (-1); -#define MIN_STACK_SIZE (5); +#define EMPTY_TOS (-1) +#define MIN_STACK_SIZE (5) struct stack_record { int capacity; int top_of_stack; elem *array; -} +}; stack create_stack(int max_elements) { @@ -55,11 +55,11 @@ void make_empty(stack s) void push(elem x, stack s) { - if(s->top_of_stack >= capacity) + if(s->top_of_stack >= s->capacity) printf("full stack"); - else + else s->array[++s->top_of_stack] = x; - + } elem top(stack s) @@ -88,3 +88,14 @@ elem top_and_pop(stack s) printf("empty stack"); return 0; } + +int main() +{ + stack s = create_stack(100); + push(1, s); + push(2, s); + push(3, s); + printf("%d\n", top_and_pop(s)); + printf("%d\n", top_and_pop(s)); + return 0; +} -- cgit v1.2.3