Skip to content
Snippets Groups Projects

Resolve "Add clear function"

Merged orestis.malaspin requested to merge 13-add-clear-function into main
All threads resolved!
Files
2
+ 15
5
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
#define DEFAULT_CAPACITY 4
@@ -87,4 +84,17 @@ int get_length(stack s) {
bool stack_is_empty(stack s)
{
return s.top == -1;
}
/**
* @brief Reset the stack's top to -1
* New values will overwrite the old ones
*
* @param s
*/
void stack_clear(stack *s)
{
s->top = -1;
s->capacity = DEFAULT_CAPACITY;
s->data = realloc(s->data, sizeof(int) * s->capacity);
}
\ No newline at end of file
Loading