Skip to content

Commit

Permalink
added is_empty function; fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
brenomatos committed Jan 3, 2020
1 parent 08d49df commit 59e6a5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data-structures/stack/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ int main(int argc, char const *argv[]) {
int k;
stack *s = NULL;
init_stack(&s);
std::cout << "its empty " << is_empty(&s) << std::endl;
push(&s,2);
push(&s,4);
push(&s,5);
Expand All @@ -25,6 +26,7 @@ int main(int argc, char const *argv[]) {
push(&s,37);


std::cout << "its empty " << is_empty(&s) << std::endl;
k = pop(&s);
printf("%d %d\n",k,s->size );
k = pop(&s);
Expand Down
4 changes: 4 additions & 0 deletions data-structures/stack/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ void free_stack(stack **s){
}
}

bool is_empty(stack **s){
return (*s)->size == 0 ? true : false;
}

#endif
1 change: 1 addition & 0 deletions data-structures/stack/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ void push(stack **s, int key);
int pop(stack **s);
void print(stack **s);
void free_stack(stack **s);
bool is_empty(stack **s);
#endif

0 comments on commit 59e6a5c

Please sign in to comment.