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
COURS_ALGO_2024_2025
Stack
Commits
f0ba7e33
Commit
f0ba7e33
authored
5 months ago
by
thibaud
Browse files
Options
Downloads
Patches
Plain Diff
ajout des assert
parent
12c9a8e4
Branches
ask-user-to-delete-exercises-on-duplicates
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stack_lib.c
+6
-2
6 additions, 2 deletions
stack_lib.c
with
6 additions
and
2 deletions
stack_lib.c
+
6
−
2
View file @
f0ba7e33
#include
<stdbool.h>
#include
<stdbool.h>
#include
<assert.h>
#define MAX_CAPACITY 500
#define MAX_CAPACITY 500
typedef
struct
_stack
{
typedef
struct
_stack
{
...
@@ -15,15 +16,18 @@ bool stack_is_empty(stack s) {
...
@@ -15,15 +16,18 @@ bool stack_is_empty(stack s) {
}
}
void
stack_push
(
stack
*
s
,
int
val
)
{
void
stack_push
(
stack
*
s
,
int
val
)
{
assert
(
s
->
top
<
MAX_CAPACITY
-
1
);
s
->
top
+=
1
;
s
->
top
+=
1
;
s
->
data
[
s
->
top
]
=
val
;
s
->
data
[
s
->
top
]
=
val
;
}
}
int
stack_pop
(
stack
*
s
)
{
int
stack_pop
(
stack
*
s
)
{
assert
(
s
->
top
>=
0
);
s
->
top
-=
1
;
s
->
top
-=
1
;
return
s
->
data
[
s
->
top
+
1
];
return
s
->
data
[
s
->
top
+
1
];
}
}
int
stack_peek
(
stack
s
)
{
int
stack_peek
(
stack
*
s
)
{
return
s
.
data
[
s
.
top
];
assert
(
s
->
top
>=
0
);
return
s
->
data
[
s
->
top
];
}
}
\ No newline at end of file
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