.
This commit is contained in:
@ -1,41 +1,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct node{
|
||||
struct node* prev;
|
||||
typedef struct Node* LIFO;
|
||||
|
||||
struct Node{
|
||||
struct Node* prev;
|
||||
void* data;
|
||||
};
|
||||
|
||||
typedef struct node* LIFO;
|
||||
|
||||
LIFO* mklifo ();
|
||||
void push(LIFO* lst , void*);
|
||||
void* pop(LIFO* lst);
|
||||
LIFO mklifo();
|
||||
void push(LIFO*, void*);
|
||||
void* pop(LIFO*);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char* t = "test";
|
||||
LIFO* lifo = mklifo();
|
||||
push(lifo, t);
|
||||
printf("%s", (char *)pop(lifo));
|
||||
|
||||
int a = 5;
|
||||
int b = 12;
|
||||
LIFO lifo = mklifo();
|
||||
|
||||
push(&lifo, &a);
|
||||
push(&lifo, &b);
|
||||
int *c = pop(&lifo);
|
||||
int *d = pop(&lifo);
|
||||
|
||||
printf("%d\n", *c);
|
||||
printf("%d\n", *d);
|
||||
}
|
||||
|
||||
LIFO *mklifo (){
|
||||
LIFO* ret = malloc(sizeof(struct node));
|
||||
return ret;
|
||||
LIFO mklifo(){
|
||||
return calloc(1, sizeof(struct Node));
|
||||
}
|
||||
|
||||
void push(LIFO *lst , void *el){
|
||||
LIFO* next = mklifo();
|
||||
void push(LIFO* lst, void* el){
|
||||
LIFO next = mklifo();
|
||||
(*lst)->data = el;
|
||||
(*next)->prev = *lst;
|
||||
lst = next;
|
||||
next->prev = *lst;
|
||||
*lst = next;
|
||||
}
|
||||
|
||||
void *pop(LIFO *lst){
|
||||
void* el;
|
||||
(*lst)->data = el;
|
||||
void *pop(LIFO* lst){
|
||||
*lst = (*lst)->prev;
|
||||
return el;
|
||||
return (*lst)->data;
|
||||
}
|
||||
|
Reference in New Issue
Block a user