diff options
| -rw-r--r-- | include/common.h | 1 | ||||
| -rw-r--r-- | src/common.c | 11 | ||||
| -rw-r--r-- | src/main/dfs.c | 7 | 
3 files changed, 18 insertions, 1 deletions
| diff --git a/include/common.h b/include/common.h index c61ac4d..9332e6e 100644 --- a/include/common.h +++ b/include/common.h @@ -15,5 +15,6 @@ struct front_item * new_front_item(double,  double, struct front_item *, struct  double dist_items(struct item *, struct item *);  int len_front(struct front_item *);  int cmp_items_ratio(const void * a, const void * b); +int cmp_items_random(const void * a, const void * b);  #endif diff --git a/src/common.c b/src/common.c index 7d9e01d..ee98bba 100644 --- a/src/common.c +++ b/src/common.c @@ -5,6 +5,8 @@  #include "structs.h"  #include "common.h" +#define RAND_MAX 1 +  struct data * input(char fp[]){    int i,j;    FILE *f; @@ -36,6 +38,15 @@ int cmp_items_ratio(const void * a, const void * b){    return -1;  } +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){ +    return 1; +  } +  return -1; +} +  void print_data(struct data * d){    int i;    printf("### PRINTING DATA - BEGINNING ###\n"); diff --git a/src/main/dfs.c b/src/main/dfs.c index ca796c5..f28f8ab 100644 --- a/src/main/dfs.c +++ b/src/main/dfs.c @@ -1,5 +1,6 @@  #include <stdio.h>  #include <time.h> +#include <stdlib.h>  #include "common.h"  #include "structs.h"  #include "dfs.h" @@ -16,12 +17,16 @@ int main(int argc, char * argv[]){    d = input(argv[1]); +  /* srand() and qsort data  */ +  srand(time(NULL)); +  qsort(d->items, d->N, sizeof(struct item), cmp_items_random); +    clock_t t = clock();    b = dfs(d);    t = clock() - t;    printf("%f,%d\n",((float)t)/CLOCKS_PER_SEC,len_front(b)); -   +    print_front(b);    free_front(b); | 
