Compare commits

...
12 Commits
3 changed files with 72 additions and 1 deletions

No files matched your search

+9
View File
@@ -1 +1,10 @@
Jonathan;89999
Jonathan;29417
player1;3999
tobih;3992
tobih;3991
tobih;3990
tobih;3989
tobih;109
tobih;100
tobih;10
+52 -1
View File
@@ -10,24 +10,75 @@
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data)
{
int tempnext = 0;
if(stack == NULL)
return NULL;
do{
if(stack->prev != NULL){
stack = stack->prev;
}
} while(stack->prev != NULL);
stack->prev = malloc(sizeof(StackNode));
tempnext = &stack;
stack = stack->prev;
stack->value = data;
stack->prev = NULL;
stack->next = tempnext;
return stack;
}
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
// freed by caller.)
StackNode *pop(StackNode *stack)
{
if(stack == NULL)
return &stack;
do{
if(stack->prev == NULL){
stack = stack->next;
stack->prev = NULL;
free(stack->prev);
} else {
stack = stack->prev;
}
} while(stack->prev != NULL);
return &stack;
}
// Returns the data of the top element.
void *top(StackNode *stack)
{
if(stack == NULL)
return &stack;
do{
if(stack->prev != NULL){
stack = stack->prev;
}
} while(stack->prev != NULL);
return stack->value;
}
// Clears stack and releases all memory.
void clearStack(StackNode *stack)
{
if(stack == NULL)
return;
do{
if(stack->prev == NULL){
stack = stack->next;
stack->prev = NULL;
free(stack->prev);
} else {
stack = stack->prev;
}
} while(stack->next != NULL);
return;
}
+11
View File
@@ -9,6 +9,17 @@ The latest element is taken from the stack. */
//TODO: passenden Datentyp als struct anlegen
//typedef int Node;
typedef void node;
typedef struct node{
void *value;
node *next;
node *prev;
}StackNode;
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data);