generated from freudenreichan/info2Praktikum-DobleSpiel
Anfänge von stack
This commit is contained in:
1 parent
c2cdde6707
commit
b9e81dbbac
3 files changed
+54
-5
No files matched your search
+11
-2
@@ -5,7 +5,10 @@
|
|||||||
/* * `push`: legt ein Element oben auf den Stack,
|
/* * `push`: legt ein Element oben auf den Stack,
|
||||||
* `pop`: entfernt das oberste Element,
|
* `pop`: entfernt das oberste Element,
|
||||||
* `top`: liefert das oberste Element zurück,
|
* `top`: liefert das oberste Element zurück,
|
||||||
* `clearStack`: gibt den gesamten Speicher frei. */
|
* `clearStack`: gibt den gesamten Speicher frei.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data)
|
StackNode *push(StackNode *stack, void *data)
|
||||||
@@ -13,6 +16,8 @@ StackNode *push(StackNode *stack, void *data)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||||
// freed by caller.)
|
// freed by caller.)
|
||||||
StackNode *pop(StackNode *stack)
|
StackNode *pop(StackNode *stack)
|
||||||
@@ -20,14 +25,18 @@ StackNode *pop(StackNode *stack)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Returns the data of the top element.
|
// Returns the data of the top element.
|
||||||
void *top(StackNode *stack)
|
void *top(StackNode *stack)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
void clearStack(StackNode *stack)
|
void clearStack(StackNode *stack)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
+7
-3
@@ -1,13 +1,17 @@
|
|||||||
#ifndef STACK_H
|
#ifndef STACK_H
|
||||||
#define STACK_H
|
#define STACK_H
|
||||||
|
|
||||||
/* A stack is a special type of queue which uses the LIFO (last in, first out) principle.
|
/* 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.
|
This means that with each new element all other elements are pushed deeper into the stack.
|
||||||
The latest element is taken from the stack. */
|
The latest element is taken from the stack. */
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
//TODO: passenden Datentyp als struct anlegen
|
|
||||||
|
|
||||||
|
//Erschaft den stack.
|
||||||
|
StackNode *create();
|
||||||
|
|
||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data);
|
StackNode *push(StackNode *stack, void *data);
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "stack.h"
|
||||||
|
#include "unity/unity.h"
|
||||||
|
|
||||||
|
|
||||||
|
//Gebastelt von Maxi
|
||||||
|
/*Unit-Tests sollen:
|
||||||
|
Integer-Werte auf den Stack legen
|
||||||
|
Integer-Werte auf den Stack wieder entfernen
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//TODO Testcases einfügen
|
||||||
|
//void test_name(void){}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
printf("============================\nStack tests\n============================\n");
|
||||||
|
RUN_TEST();
|
||||||
|
|
||||||
|
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user