From e7fcca35efae60ca2e24225b046ab4e9a801b031 Mon Sep 17 00:00:00 2001 From: Alexandre Jesus Date: Thu, 22 Sep 2016 02:02:20 +0100 Subject: Create tree structure, adapt dfs to use tree (with iterative technique), fix random sort --- src/common.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index ee98bba..7a8b316 100644 --- a/src/common.c +++ b/src/common.c @@ -5,8 +5,6 @@ #include "structs.h" #include "common.h" -#define RAND_MAX 1 - struct data * input(char fp[]){ int i,j; FILE *f; @@ -39,9 +37,7 @@ int cmp_items_ratio(const void * a, const void * b){ } int cmp_items_random(const void *a, const void *b) { - struct item c = *(struct item *)a; - struct item d = *(struct item *)b; - if(rand() > 0.5){ + if(rand() % 2 == 0){ return 1; } return -1; @@ -94,6 +90,18 @@ struct front_item * new_front_item(double p, double w, struct front_item * prev, return f; } +struct tree_item * new_tree_item(long int depth, long int itemi, double w, double p, struct tree_item * prev, struct tree_item * next) { + struct tree_item * t = (struct tree_item *)malloc(sizeof(struct tree_item)); + t->depth = depth; + t->itemi = itemi; + t->values.w = w; + t->values.p = p; + t->prev = prev; + t->next = next; + + return t; +} + double dist_items(struct item * a, struct item * b){ return sqrt((a->p - b->p)*(a->p - b->p) + (a->w - b->w)*(a->w - b->w)); } -- cgit v1.2.3