generated from freudenreichan/info2Praktikum-DobleSpiel
finale version kommentare hinzugefügt
This commit is contained in:
parent
8c95340c77
commit
02c7d7348a
@ -65,7 +65,7 @@ void *nextTreeData(TreeNode *root)
|
|||||||
static StackNode *stack = NULL;
|
static StackNode *stack = NULL;
|
||||||
static TreeNode* currentNode = NULL;
|
static TreeNode* currentNode = NULL;
|
||||||
void* result;
|
void* result;
|
||||||
|
//erste initialisierung mit NULL
|
||||||
if(stack==NULL && root != NULL){
|
if(stack==NULL && root != NULL){
|
||||||
currentNode = root;
|
currentNode = root;
|
||||||
while(currentNode != NULL){
|
while(currentNode != NULL){
|
||||||
|
|||||||
@ -6,7 +6,8 @@ void setUp(void){}
|
|||||||
void tearDown(void){}
|
void tearDown(void){}
|
||||||
|
|
||||||
void TEST_BINTREE(){
|
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 output[8];
|
||||||
int len = 8;
|
int len = 8;
|
||||||
TreeNode* root = NULL;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 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
|
// Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while
|
||||||
// creating random numbers.
|
// creating random numbers.
|
||||||
unsigned int *createNumbers(unsigned int len)
|
unsigned int* createNumbers(unsigned int len)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
unsigned int* numbers =malloc(sizeof(unsigned int) * len);
|
unsigned int* numbers =malloc(sizeof(unsigned int) * len);
|
||||||
@ -26,7 +26,7 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
|
|
||||||
if(numbers == NULL)return NULL;
|
if(numbers == NULL)return NULL;
|
||||||
|
|
||||||
|
//array mit verschiedenen zufallszahlen befüllen
|
||||||
while(generated<len){
|
while(generated<len){
|
||||||
|
|
||||||
numberTemp = (rand() % (2*len))+1;
|
numberTemp = (rand() % (2*len))+1;
|
||||||
@ -42,7 +42,7 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Duplikat erstellen
|
||||||
int DuplicateId;
|
int DuplicateId;
|
||||||
int DuplicatePlace;
|
int DuplicatePlace;
|
||||||
|
|
||||||
|
|||||||
8
stack.c
8
stack.c
@ -8,7 +8,7 @@
|
|||||||
* `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) //Neuer Knoten wird oben auf den Stack gelegt
|
||||||
{
|
{
|
||||||
StackNode* stacknew = malloc(sizeof(StackNode));
|
StackNode* stacknew = malloc(sizeof(StackNode));
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ 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) //Oberster Knoten wird gelöscht, der darunter wird zurückgegeben
|
||||||
{
|
{
|
||||||
StackNode *ptr = stack->prev;
|
StackNode *ptr = stack->prev;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ 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) //Daten des obersten Knoten werden ausgelesen
|
||||||
{
|
{
|
||||||
|
|
||||||
return stack->value;
|
return stack->value;
|
||||||
@ -37,7 +37,7 @@ void *top(StackNode *stack)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
void clearStack(StackNode *stack)
|
void clearStack(StackNode *stack) //gesamter Stack wird gefereed
|
||||||
{
|
{
|
||||||
StackNode *ptr = stack;
|
StackNode *ptr = stack;
|
||||||
|
|
||||||
|
|||||||
47
timer.c
47
timer.c
@ -1,6 +1,10 @@
|
|||||||
|
#define _POSIX_C_SOURCE 199309L
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
#if __APPLE__
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/*#if __APPLE__
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
static struct timespec start = {0, 0};
|
static struct timespec start = {0, 0};
|
||||||
|
|
||||||
@ -38,18 +42,55 @@ static clock_t startClocks = 0;
|
|||||||
void startTimer()
|
void startTimer()
|
||||||
{
|
{
|
||||||
startClocks = clock();
|
startClocks = clock();
|
||||||
|
|
||||||
|
printf("\nstartclocks: %ld\n", startClocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the time in seconds since startTimer() was called.
|
// Returns the time in seconds since startTimer() was called.
|
||||||
double stopTimer()
|
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)
|
if(startClocks > 0)
|
||||||
startClocks = 0;
|
startClocks = 0;
|
||||||
else
|
else
|
||||||
measuredSeconds = -1;
|
measuredSeconds = -1;
|
||||||
|
|
||||||
|
printf("measuredsecondes: %f\n", measuredSeconds);
|
||||||
|
|
||||||
return measuredSeconds;
|
return measuredSeconds;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|||||||
6
timer.h
6
timer.h
@ -1,6 +1,6 @@
|
|||||||
#ifndef TIMER_H
|
#ifndef TIMER_H
|
||||||
#define TIMER_H
|
#define TIMER_H
|
||||||
|
#include <time.h>
|
||||||
// Usage of time.h: clock() returns the number of clock ticks since program start. CLOCKS_PER_SECONDS represents the
|
// 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.
|
// number of clock ticks per second.
|
||||||
|
|
||||||
@ -10,4 +10,8 @@ void startTimer();
|
|||||||
// Returns the time in seconds since startTimer() was called.
|
// Returns the time in seconds since startTimer() was called.
|
||||||
double stopTimer();
|
double stopTimer();
|
||||||
|
|
||||||
|
struct timespec {
|
||||||
|
time_t tv_sec;
|
||||||
|
long tv_nsec;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user