Skip to content
Snippets Groups Projects
Commit 981decc1 authored by ines.maya's avatar ines.maya
Browse files

fais un main pour tester et mis les includes dans le .h et doit juste voir un truc

parent 56f989db
No related branches found
No related tags found
1 merge request!16Resolve "Add pop function"
This commit is part of merge request !16. Comments created here will be created in the context of that merge request.
main.c 0 → 100644
#include "stack.h"
int main(){
stack s;
int value = 0;
stack_init(&s);
// stack_is_empty(stack s)
stack_peek(s, &value);
stack_pop(&s, &value);
}
\ No newline at end of file
......@@ -17,11 +17,17 @@ void stack_peek(stack s, int *value){
}
// depile
void stack_pop(stack *s, int *val){
void stack_pop(stack *s, int *value){
if (stack_is_empty(*s)){
return;
}
*val = s->data[s->top];
*value = s->data[s->top];
s->top -= 1;
printf("pop : %d, top : %d\n", s->data[s->top],s->top);
// si capacite 2x trop grande, on la rend plus petite
if (s->capacity > 2*s->top){
s->capacity = s->top;
s->data = realloc(s, sizeof(int)*s->capacity);
}
}
......@@ -16,4 +16,6 @@ typedef struct _stack {
void stack_init(stack *s);
void stack_peek(stack s, int *value);
void stack_pop(stack *s, int *value);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment