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

tous les test ok

parent e7553071
No related branches found
No related tags found
1 merge request!16Resolve "Add pop function"
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
int main(){ int main(){
stack s; stack s;
int value = 0; int value = 13;
stack_init(&s); stack_init(&s);
for (int i = 0; i < s.capacity; i++){
s.top += 1; s.top += 1;
s.data[s.top] = i; s.data[s.top] = value;
printf("push : %d\n", s.data[s.top]);
} s.top += 1;
s.data[s.top] = value+1;
// stack_is_empty(stack s)
stack_pop(&s, &value); stack_pop(&s, &value);
stack_peek(s, &value);
free(s.data); free(s.data);
s.data = NULL; s.data = NULL;
......
...@@ -14,6 +14,7 @@ void stack_peek(stack s, int *value){ ...@@ -14,6 +14,7 @@ void stack_peek(stack s, int *value){
if (!stack_is_empty(s)) { if (!stack_is_empty(s)) {
*value = s.data[s.top]; *value = s.data[s.top];
} }
printf("peek : value %d, top : %d\n", s.data[s.top],s.top);
} }
// depile // depile
...@@ -29,10 +30,4 @@ void stack_pop(stack *s, int *value){ ...@@ -29,10 +30,4 @@ void stack_pop(stack *s, int *value){
*value = s->data[s->top]; *value = s->data[s->top];
printf("pop : %d, top : %d\n", s->data[s->top],s->top); printf("pop : %d, top : %d\n", s->data[s->top],s->top);
s->top -= 1; s->top -= 1;
// // 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);
// }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment