diff --git a/bintree.c b/bintree.c index 1201de5..a5bc809 100644 --- a/bintree.c +++ b/bintree.c @@ -65,7 +65,7 @@ void *nextTreeData(TreeNode *root) static StackNode *stack = NULL; static TreeNode* currentNode = NULL; void* result; - + //erste initialisierung mit NULL if(stack==NULL && root != NULL){ currentNode = root; while(currentNode != NULL){ diff --git a/bintreeTests.c b/bintreeTests.c index 21efac5..701dd62 100644 --- a/bintreeTests.c +++ b/bintreeTests.c @@ -6,7 +6,8 @@ void setUp(void){} void tearDown(void){} void TEST_BINTREE(){ - int input[8]={1,2,3,4,5,6,7,8}; + int input[8]={7,3,2,4,8,6,1,5}; + int expected[8]={1,2,3,4,5,6,7,8}; int output[8]; int len = 8; TreeNode* root = NULL; @@ -21,7 +22,7 @@ void TEST_BINTREE(){ } - TEST_ASSERT_INT_ARRAY_WITHIN(0, input, output, 8); + TEST_ASSERT_INT_ARRAY_WITHIN(0, expected, output, 8); } diff --git a/numbers.c b/numbers.c index 5074138..3403117 100644 --- a/numbers.c +++ b/numbers.c @@ -14,7 +14,7 @@ // Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries. // Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while // creating random numbers. -unsigned int *createNumbers(unsigned int len) +unsigned int* createNumbers(unsigned int len) { srand(time(NULL)); unsigned int* numbers =malloc(sizeof(unsigned int) * len); @@ -26,7 +26,7 @@ unsigned int *createNumbers(unsigned int len) if(numbers == NULL)return NULL; - + //array mit verschiedenen zufallszahlen befüllen while(generatedprev; @@ -29,7 +29,7 @@ StackNode *pop(StackNode *stack) } // Returns the data of the top element. -void *top(StackNode *stack) +void *top(StackNode *stack) //Daten des obersten Knoten werden ausgelesen { return stack->value; @@ -37,7 +37,7 @@ void *top(StackNode *stack) } // Clears stack and releases all memory. -void clearStack(StackNode *stack) +void clearStack(StackNode *stack) //gesamter Stack wird gefereed { StackNode *ptr = stack; diff --git a/timer.c b/timer.c index fd8f6c1..3e13691 100644 --- a/timer.c +++ b/timer.c @@ -1,6 +1,10 @@ +#define _POSIX_C_SOURCE 199309L #include "timer.h" -#if __APPLE__ +#include +#include + +/*#if __APPLE__ #include static struct timespec start = {0, 0}; @@ -38,18 +42,55 @@ static clock_t startClocks = 0; void startTimer() { startClocks = clock(); + + printf("\nstartclocks: %ld\n", startClocks); } // Returns the time in seconds since startTimer() was called. double stopTimer() { - double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC; + clock_t endClocks = clock(); + printf("\nendclocks: %ld\n", endClocks); + printf("\ndeltatimer: %ld\n", (endClocks - startClocks)); + + printf("CLOCKS_PER_SECONDS: %ld\n", CLOCKS_PER_SEC); + double measuredSeconds = (double)(endClocks - startClocks) / CLOCKS_PER_SEC; if(startClocks > 0) startClocks = 0; else measuredSeconds = -1; + printf("measuredsecondes: %f\n", measuredSeconds); + return measuredSeconds; } -#endif \ No newline at end of file + + + +#endif*/ + +static struct timespec start; + +void startTimer() { + + clock_gettime(CLOCK_MONOTONIC, &start); +} + +static struct timespec end; +double stopTimer() { + + clock_gettime(CLOCK_MONOTONIC, &end); + + double measuredseconds = (double)(end.tv_sec - start.tv_sec) + (double)(end.tv_nsec - start.tv_nsec) * 0.000000001; + if (start.tv_sec>0 || start.tv_nsec>0){ + end.tv_nsec = 0; + end.tv_sec =0; + start.tv_sec = 0; + start.tv_nsec = 0; + }else { + measuredseconds = -1; + } + + return measuredseconds; +} diff --git a/timer.h b/timer.h index 180f8ac..2e46177 100644 --- a/timer.h +++ b/timer.h @@ -1,6 +1,6 @@ #ifndef TIMER_H #define TIMER_H - +#include // Usage of time.h: clock() returns the number of clock ticks since program start. CLOCKS_PER_SECONDS represents the // number of clock ticks per second. @@ -10,4 +10,8 @@ void startTimer(); // Returns the time in seconds since startTimer() was called. double stopTimer(); +struct timespec { + time_t tv_sec; + long tv_nsec; +}; #endif