aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c18
1 files changed, 13 insertions, 5 deletions
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));
}