forked from freudenreichan/info2Praktikum-DobleSpiel
Ersten Stackfunktionen
This commit is contained in:
1 parent
dbe47dd9f1
commit
4fc1a684cb
1 file changed
+27
-1
+27
-1
@@ -17,17 +17,43 @@ StackNode *push(StackNode *stack, void *data)
|
|||||||
// freed by caller.)
|
// freed by caller.)
|
||||||
StackNode *pop(StackNode *stack)
|
StackNode *pop(StackNode *stack)
|
||||||
{
|
{
|
||||||
|
if(stack == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
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.
|
// Returns the data of the top element.
|
||||||
void *top(StackNode *stack)
|
void *top(StackNode *stack)
|
||||||
{
|
{
|
||||||
|
if(stack == NULL)
|
||||||
|
return &stack;
|
||||||
|
|
||||||
|
do{
|
||||||
|
if(stack->prev == NULL){
|
||||||
|
stack = stack->next;
|
||||||
|
}
|
||||||
|
} while(stack->prev != NULL)
|
||||||
|
return stack->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
void clearStack(StackNode *stack)
|
void clearStack(StackNode *stack)
|
||||||
{
|
{
|
||||||
|
if(stack == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
do{
|
||||||
|
if(stack->)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user