Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
algorithmique
lib_2021_malaspinas
stack
Commits
65c59a43
Commit
65c59a43
authored
Dec 07, 2021
by
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
stack.c
View file @
65c59a43
#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
stack.h
View file @
65c59a43
#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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment