31 lines
1002 B
C
31 lines
1002 B
C
#ifndef STACK_H //if not defined - Code nur ausgeführt wenn nicht definiert
|
|
#define STACK_H
|
|
|
|
/* A stack is a special type of queue which uses the LIFO (last in, first out) principle.
|
|
This means that with each new element all other elements are pushed deeper into the stack.
|
|
The latest element is taken from the stack. */
|
|
|
|
#include <stdlib.h>
|
|
|
|
//TODO: passenden Datentyp als struct anlegen
|
|
|
|
// Datentyp für Stack-Element
|
|
typedef struct StackNode {
|
|
void *data; // Zeiger auf Nutzdaten (Datentyp unbekannt)
|
|
struct StackNode *next; // Zeiger auf das nächste Element
|
|
} StackNode;
|
|
|
|
// Pushes Daten als Zeiger auf den Stack.
|
|
StackNode *push(StackNode *stack, void *data);
|
|
|
|
// Löscht das oberste Element des Stacks (letztes hinzugefügtes) und gibt den Speicher frei.
|
|
StackNode *pop(StackNode *stack);
|
|
|
|
// Gibt den Wert des obersten Elements zurück.
|
|
void *top(StackNode *stack);
|
|
|
|
// Leert den Stack und gibt den gesamten Speicher frei.
|
|
void clearStack(StackNode *stack);
|
|
|
|
#endif
|