This commit is contained in:
pvtrx 2025-12-19 08:43:35 +01:00
parent b3279a2486
commit d06168f6c1
2 changed files with 7 additions and 10 deletions

View File

@ -56,10 +56,10 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
// push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root)
{
/* Iterator state kept across calls (strtok-style). */
static StackNode *iterStack = NULL;
/* Starting a new traversal: reset stack and seed with root's left spine. */
// Start of traversal
if (root != NULL) {
clearStack(iterStack);
iterStack = NULL;
@ -69,16 +69,16 @@ void *nextTreeData(TreeNode *root)
}
}
/* No more elements. */
// Stops if no elements left
if (iterStack == NULL) {
return NULL;
}
/* Visit next node in-order. */
// Pop the top node
TreeNode *node = (TreeNode *)top(iterStack);
iterStack = pop(iterStack);
/* After visiting, push the left spine of the right subtree. */
// select node one to the right --> push all lefts
for (TreeNode *n = node->right; n != NULL; n = n->left) {
iterStack = push(iterStack, n);
}

View File

@ -6,12 +6,9 @@
#include <stdlib.h>
#include <string.h>
/* ===================== Test-Fixture ===================== */
void setUp(void) { /* nothing */ }
void tearDown(void){ /* nothing */ }
/* ===================== Helpers ===================== */
// Zählt Vorkommen eines Werts im Array
static unsigned count_occurrences(const unsigned int *arr, unsigned int len, unsigned int value)
{
@ -58,7 +55,7 @@ static void assert_numbers_properties(const unsigned int *arr, unsigned int len,
if (dup_out) *dup_out = dupVal;
}
/* ===================== Einzeltests ===================== */
// Einzeltests
// createNumbers: len < 2 -> NULL
static void test_createNumbers_len_too_small(void)
@ -144,7 +141,7 @@ static void test_getDuplicate_does_not_modify_input(void)
TEST_ASSERT_EQUAL_MEMORY(original, arr, sizeof arr);
}
/* ===================== Runner ===================== */
//Runner
int main(void)
{