Rating Finished

This commit is contained in:
stitchy 2023-10-15 15:55:30 -07:00
parent 1f68e6be58
commit 0fb4a5b117
Signed by: stitchy
SSH key fingerprint: SHA256:yz2SoxdnY67tfY5Jzb0f2v8f5W3o/IF359kbcquWip8
2 changed files with 83 additions and 7 deletions

View file

@ -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) { void lang_print(struct csv* data, void* val) {
for(int i = 0; i < data->numlang; i++) { for(int i = 0; i < data->numlang; i++) {
@ -117,3 +112,85 @@ void movie_lang(struct node* head) {
printf("\n"); 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");
}

View file

@ -50,8 +50,7 @@ void iterate_nodes(struct node* head, void *func (void*, void*), void* val) {
if(!head) if(!head)
return; return;
if(head->node) func(head->data, val);
func(head->data, val);
struct node* temp = head; struct node* temp = head;