2023-10-12 16:07:28 +02:00
|
|
|
#include "stack.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
struct stack_t {
|
2023-12-10 15:48:26 +01:00
|
|
|
int size;
|
|
|
|
int * tableau;
|
|
|
|
int index;
|
2023-10-12 16:07:28 +02:00
|
|
|
};
|
|
|
|
|
2023-12-10 15:48:26 +01:00
|
|
|
|
2023-10-12 16:07:28 +02:00
|
|
|
stack_t * stack_create( int max_size)
|
|
|
|
{
|
2023-12-10 15:48:26 +01:00
|
|
|
stack_t new;
|
|
|
|
new.size = max_size;
|
|
|
|
new.index = index;
|
|
|
|
return *new;
|
2023-10-12 16:07:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int stack_destroy(stack_t * s)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int stack_push(stack_t *s,int val)
|
|
|
|
{
|
2023-12-10 15:48:26 +01:00
|
|
|
if (s->index == 0){
|
|
|
|
s->tableau = malloc(s->size * sizeof(int);
|
|
|
|
}
|
|
|
|
if (s->index == s->size - 1){
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
s->tableau[value]=val;
|
|
|
|
s->value = s->value + 1;
|
|
|
|
return EXIT_SUCCESS;
|
2023-10-12 16:07:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int stack_pop(stack_t *s,int * val)
|
|
|
|
{
|
2023-12-10 15:48:26 +01:00
|
|
|
if (s->index == 0){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
s->
|
2023-10-12 16:07:28 +02:00
|
|
|
}
|
|
|
|
|