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

premiere version de pop, a verifier

parent 6e8cc6fa
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.
stack.c 0 → 100644
#include "stack.h"
void stack_init(stack *s){
s->top = -1;
s->capacity = DEFAULT_CAPACITY;
s->data = malloc(sizeof(int) * DEFAULT_CAPACITY);
}
bool stack_is_empty(stack s){
return s.top == -1;
}
void stack_peek(stack s, int *value){
if (!stack_is_empty(s)) {
*value = s.data[s.top];
}
}
// depile
void stack_pop(stack *s, int *val){
if (stack_is_empty(*s)){
return;
}
*val = s->data[s->top];
s->top -= 1;
printf("pop : %d, top : %d\n", s->data[s->top],s->top);
}
#ifndef _STACK_H_
#define _STACK_H_
#include <stdio.h>
#include <stdlib.h>
#include "stdbool.h"
#define DEFAULT_CAPACITY 4
typedef struct _stack {
int *data;
int capacity;
int top;
} stack;
void stack_init(stack *s);
void stack_peek(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