Skip to content
Snippets Groups Projects
Commit 3126857e authored by orestis.malaspin's avatar orestis.malaspin
Browse files

Resolve "Add is empty function"

parent 287ed7af
No related branches found
No related tags found
1 merge request!19Resolve "Add is empty function"
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "stack.h" #include "stack.h"
...@@ -75,3 +78,13 @@ int get_length(stack s) { ...@@ -75,3 +78,13 @@ int get_length(stack s) {
return s.top + 1; return s.top + 1;
} }
/**
* @brief Check if a stack is empty
*
* @param s
* @return bool - true if stack is empty, false otherwise
*/
bool stack_is_empty(stack s)
{
return s.top == -1;
}
\ No newline at end of file
#ifndef _STACK_H_ #ifndef _STACK_H_
#define _STACK_H_ #define _STACK_H_
typedef struct _stack { typedef struct _stack {
int *data; int *data;
int capacity; int capacity;
...@@ -17,6 +16,7 @@ void stack_pop(stack *s, int *value); ...@@ -17,6 +16,7 @@ void stack_pop(stack *s, int *value);
void stack_peek(stack s, int *value); void stack_peek(stack s, int *value);
void stack_clone(stack s, stack *clone); void stack_clone(stack s, stack *clone);
int get_length(stack s); int get_length(stack s);
bool stack_is_empty(stack s);
void stack_print(const stack s); void stack_print(const stack s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment