added an is_empty function to the stack.

This commit is contained in:
Andrew Lalis 2017-05-23 11:21:38 +02:00
parent 2787de465b
commit 167b450ce3
2 changed files with 15 additions and 0 deletions

View File

@ -11,11 +11,18 @@ A handy collection of C algorithms compiled into one header file for use anywher
### Functions ### Functions
```c ```c
//Creates new stack.
void new(); void new();
//Frees stack memory.
void free(Stack *s); void free(Stack *s);
//Pushes item to top of the stack.
void push(item, Stack *s); void push(item, Stack *s);
//Removes item on top of the stack and returns it.
item pop(Stack *s); item pop(Stack *s);
//Prints stack size, memory usage.
void print(Stack s); void print(Stack s);
//Returns 1 if empty stack, 0 otherwise.
int is_empty(Stack s);
``` ```
### Description ### Description

View File

@ -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)); 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 #endif