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

Merge branch '9-add-destroy-function' into 'main'

Resolve "Add destroy function"

Closes #9

See merge request !18
parents 25c9c05a bec8b7b6
No related branches found
No related tags found
1 merge request!18Resolve "Add destroy function"
...@@ -11,6 +11,13 @@ void stack_init(stack *s) ...@@ -11,6 +11,13 @@ void stack_init(stack *s)
s->data = malloc(sizeof(int) * DEFAULT_CAPACITY); s->data = malloc(sizeof(int) * DEFAULT_CAPACITY);
} }
void stack_destroy(stack *s){
free(s->data);
s->data = NULL;
s->capacity = -1;
s->top = -1;
}
void stack_peek(stack s, int *value){ void stack_peek(stack s, int *value){
if (!stack_is_empty(s)) { if (!stack_is_empty(s)) {
*value = s.data[s.top]; *value = s.data[s.top];
......
...@@ -9,6 +9,8 @@ typedef struct _stack { ...@@ -9,6 +9,8 @@ typedef struct _stack {
void stack_init(stack *stack); void stack_init(stack *stack);
void stack_destroy(stack *s);
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment