42 lines
584 B
C
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;
|
||
|
}
|