Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
algorithmique
lib_2021_malaspinas
stack
Commits
65c59a43
Commit
65c59a43
authored
3 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Plain Diff
Merge branch '13-add-clear-function' into 'main'
Resolve "Add clear function" Closes
#13
See merge request
!20
parents
f39dc138
d2818fb7
No related branches found
No related tags found
1 merge request
!20
Resolve "Add clear function"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
stack.c
+15
-5
15 additions, 5 deletions
stack.c
stack.h
+5
-0
5 additions, 0 deletions
stack.h
with
20 additions
and
5 deletions
stack.c
+
15
−
5
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
This diff is collapsed.
Click to expand it.
stack.h
+
5
−
0
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment