Skip to content
Snippets Groups Projects
Commit f0ba7e33 authored by thibaud's avatar thibaud
Browse files

ajout des assert

parent 12c9a8e4
Branches ask-user-to-delete-exercises-on-duplicates
No related tags found
No related merge requests found
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment