From 0fb4a5b117647d0f5ef5d03664985939eb04680c Mon Sep 17 00:00:00 2001 From: stitchy Date: Sun, 15 Oct 2023 15:55:30 -0700 Subject: [PATCH] Rating Finished --- movies/movies.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--- movies/node.c | 3 +- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/movies/movies.c b/movies/movies.c index 66f540e..852bb0e 100644 --- a/movies/movies.c +++ b/movies/movies.c @@ -81,11 +81,6 @@ void movie_year(struct node* head) { } -void movie_rate(struct node* head) { - printf("stub\n"); - -} - void lang_print(struct csv* data, void* val) { for(int i = 0; i < data->numlang; i++) { @@ -117,3 +112,85 @@ void movie_lang(struct node* head) { printf("\n"); } + +void check_year(int* data, int* year) { + + if(*data == *year) + haschanged = 1; + + //printf("%d, %d\n",*data, *year); + +} + +void find_year(struct csv* data, void* year) { + + void* f = &check_year; + + haschanged = 0; + iterate_nodes(year, f, &data->year); + + if(!haschanged) { + appendv_node(year, &data->year); + //printf("Change Val: %d\n", data->year); + } + + haschanged = 0; + +} + +void print_node(int* val, char* garbage) { + + printf("%s\n", garbage); +} + +void print_rating(struct csv* data, struct csv** val) { + + if(val[0] == NULL) { + if(data->year == haschanged) + val[0] = data; + return; + } + + if(data->rating > val[0]->rating + && data->year == haschanged) + val[0] = data; + +} + +void index_nodes(int* val, void* head) { + + haschanged = *val; + + struct csv ** cur_val = malloc(sizeof(struct csv*)); + cur_val[0] = NULL; + + void* f = &print_rating; + + iterate_nodes(head, f, cur_val); + + printf("%d %2.1f %s\n", cur_val[0]->year, cur_val[0]->rating, cur_val[0]->title); + + haschanged = 0; + +} + +void movie_rate(struct node* head) { + + struct csv* temp = head->data; + + struct node* year = appendv_node(NULL, &temp->year); + + void* f = &find_year; + + // Make a list of every year that has a movie + iterate_nodes(head, f, year); + + void* tempish = &index_nodes; + + + // Iterate though every year and find the highest rating + iterate_nodes(year, tempish, head); + + printf("\n"); +} + diff --git a/movies/node.c b/movies/node.c index 1ccfa7d..698180c 100644 --- a/movies/node.c +++ b/movies/node.c @@ -50,8 +50,7 @@ void iterate_nodes(struct node* head, void *func (void*, void*), void* val) { if(!head) return; - if(head->node) - func(head->data, val); + func(head->data, val); struct node* temp = head;