Commit 65c59a43 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

Merge branch '13-add-clear-function' into 'main'

Resolve "Add clear function"

Closes #13

See merge request !20
parents f39dc138 d2818fb7
#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
#ifndef _STACK_H_
#define _STACK_H_
#include <stdbool.h>
typedef struct _stack {
int *data;
int capacity;
......@@ -17,6 +21,7 @@ void stack_peek(stack s, int *value);
void stack_clone(stack s, stack *clone);
int get_length(stack s);
bool stack_is_empty(stack s);
void stack_clear(stack *s) ;
void stack_print(const stack s);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment