From 167b450ce3131bd9c92ac7237e1690d6706c6745 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Tue, 23 May 2017 11:21:38 +0200 Subject: [PATCH] added an is_empty function to the stack. --- README.md | 7 +++++++ source/handystack.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index a285e5d..2a914c8 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,18 @@ A handy collection of C algorithms compiled into one header file for use anywher ### Functions ```c +//Creates new stack. void new(); +//Frees stack memory. void free(Stack *s); +//Pushes item to top of the stack. void push(item, Stack *s); +//Removes item on top of the stack and returns it. item pop(Stack *s); +//Prints stack size, memory usage. void print(Stack s); +//Returns 1 if empty stack, 0 otherwise. +int is_empty(Stack s); ``` ### Description diff --git a/source/handystack.h b/source/handystack.h index 8bc259b..aec8afb 100644 --- a/source/handystack.h +++ b/source/handystack.h @@ -114,4 +114,12 @@ void TEMPLATE(print,STACK_CONTAINER)(STACK_CONTAINER s){ printf("\tStack: \tItems: %d, Allocated Size: %d, Bytes used: %lu\n", s.top, s.size, s.size*sizeof(STACK_TYPE)); } +/* +Stack check Empty: + returns 1 if the stack is empty, false if there is at least one item. +*/ +int TEMPLATE(is_empty,STACK_CONTAINER)(STACK_CONTAINER s){ + return (s.top == 0); +} + #endif \ No newline at end of file