cours_progra/bac2/os/chap2/ex5.c
Debucquoy b0f02b0d5d
.
2023-10-18 20:27:40 +02:00

42 lines
584 B
C

#include <stdlib.h>
#include <stdio.h>
struct node{
struct node* prev;
void* data;
};
typedef struct node* LIFO;
LIFO* mklifo ();
void push(LIFO* lst , void*);
void* pop(LIFO* lst);
int main(void)
{
char* t = "test";
LIFO* lifo = mklifo();
push(lifo, t);
printf("%s", (char *)pop(lifo));
}
LIFO *mklifo (){
LIFO* ret = malloc(sizeof(struct node));
return ret;
}
void push(LIFO *lst , void *el){
LIFO* next = mklifo();
(*lst)->data = el;
(*next)->prev = *lst;
lst = next;
}
void *pop(LIFO *lst){
void* el;
(*lst)->data = el;
*lst = (*lst)->prev;
return el;
}