Compare commits

..

No commits in common. "600c414daa9a95820b1d3d89315ba6828b731b16" and "8a29c029ff41bb3c54fd4871a0e6d1b079ae4932" have entirely different histories.

7 changed files with 17 additions and 104 deletions

View File

@ -1,6 +0,0 @@
{
"files.associations": {
"stdio.h": "c",
"unity.h": "c"
}
}

View File

@ -17,20 +17,11 @@ typedef struct node
TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate);
// Iterates over the tree given by root. Follows the usage of strtok. If tree is NULL, the next entry of the last tree given is returned in ordering direction.
// Use your implementation of a stack to organize the iterator. Push the root node and all left nodes first. On returning the next element,
// push the right top node and push all its left nodes.
// Hilfsfunktion pushAllLeft (node) auf rechten nachfolger
// wenn neuer Baum dann pushallleft auf wurzel
// immer aufräumen!!!
// kein vorsortiertes array, sonst entarteter Baum
// push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root);
// Releases all memory resources (including data copies).
// sortierte Ausgabe
// aufrufen wie mit strtok
// welcher Baum durchlaufen
// immer null aufrufen bis fertig durchlaufen weil null zurückgegeben wird
void clearTree(TreeNode *root);
// Returns the number of entries in the tree given by root.
unsigned int treeSize(const TreeNode *root);
//rekursiv die Anzahl der gesetzten Knoten ermitteln
#endif

View File

@ -36,11 +36,8 @@ $(program_obj_filesobj_files): %.o: %.c
# Unit Tests
# --------------------------
test_numbers:
$(CC) -o test_numbers test_numbers.c numbers.c $(unityfolder)/unity.c $(FLAGS)
$(CC) -o test_numbers test__numbers.c numbers.c $(unityfolder)/unity.c $(FLAGS)
test_stack:
$(CC) -o test_stack test_stack.c stack.c $(unityfolder)/unity.c $(FLAGS)
# --------------------------
# Clean
# --------------------------

54
stack.c
View File

@ -1,65 +1,39 @@
#include <stdlib.h>
#include "stack.h"
// TODO: grundlegende Stackfunktionen implementieren:
//TODO: grundlegende Stackfunktionen implementieren:
/* * `push`: legt ein Element oben auf den Stack,
* `pop`: entfernt das oberste Element,
* `top`: liefert das oberste Element zurück,
* `clearStack`: gibt den gesamten Speicher frei. */
static StackNode *createNewElement()
{
return malloc(sizeof(StackNode));
}
* `pop`: entfernt das oberste Element,
* `top`: liefert das oberste Element zurück,
* `clearStack`: gibt den gesamten Speicher frei. */
// Pushes data as pointer onto the stack.
typedef struct stackNode
{
void *data;
struct stackNode *next;
} StackNode;
StackNode *push(StackNode *stack, void *data)
{
StackNode *node = createNewElement();
if (node != NULL)
{
node->data = data;
node->next = stack;
return node;
}
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)
{
StackNode *currentElement = stack;
stack = stack->next;
free(currentElement);
}
return stack;
}
// Returns the data of the top element.
void *top(StackNode *stack)
{
if (stack != NULL)
{
return stack->data;
}
return NULL;
}
// Clears stack and releases all memory.
void clearStack(StackNode *stack)
{
StackNode *nextElement = stack;
while (stack != NULL)
{
nextElement = stack->next;
free(stack);
stack = nextElement;
}
}
}

View File

@ -8,11 +8,6 @@ The latest element is taken from the stack. */
#include <stdlib.h>
//TODO: passenden Datentyp als struct anlegen
typedef struct stackNode
{
void *data;
struct stackNode *next;
} StackNode;
// Pushes data as pointer onto the stack.
StackNode *push(StackNode *stack, void *data);

View File

@ -1,38 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "unity/unity.h"
#include "stack.h"
void test_stackOrderIsCorrect()
{
int expectedValues[] = {1, 2, 3, 4};
const unsigned int exprectedLen = sizeof(expectedValues) / sizeof(expectedValues[0]);
unsigned int observedLen = 0;
StackNode *stack = NULL;
for(int i = 0; i < exprectedLen; i++)
{
stack = push(stack, &expectedValues[i]);
}
for(int i = exprectedLen-1; i >= 0 && stack != NULL; i--)
{
TEST_ASSERT_EQUAL(expectedValues[i], *(int *)top(stack));
observedLen++;
stack = pop(stack);
}
TEST_ASSERT_EQUAL_UINT32(exprectedLen, observedLen);
clearStack(stack);
}
void setUp(void) {}
void tearDown(void) {}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_stackOrderIsCorrect);
return UNITY_END();
}