From b33f7a0db34749b33dcbad5dac3cc3384405097a Mon Sep 17 00:00:00 2001 From: Kozar Date: Fri, 8 Nov 2024 13:23:35 +0000 Subject: [PATCH 1/4] Initializacia --- cv6/a_station.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cv6/a_station.c b/cv6/a_station.c index 8f659d6..030e70d 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -10,12 +10,20 @@ struct station* create_station(){ } void destroy_station(struct station* station){ + for (int i = 0; i < station->track_count; i++) { + struct car* current = station->tracks[i]; + while (current) { + struct car* temp = current; + current = current->next; + free(temp); + } + } + free(station->tracks); + free(station); } int select_track(struct station* station, const char* target){ - return 0; } - void add_target_capacity(struct station* station,const char* target, int capacity){ } From 1bd6f8da281df96c6dcd643629cc9a1e6873e50b Mon Sep 17 00:00:00 2001 From: Kozar Date: Fri, 8 Nov 2024 13:24:45 +0000 Subject: [PATCH 2/4] Initializacia --- cv6/a_station.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cv6/a_station.c b/cv6/a_station.c index 030e70d..f483f16 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -1,3 +1,4 @@ +#include #include "a_station.h" #include #include @@ -23,7 +24,14 @@ void destroy_station(struct station* station){ } int select_track(struct station* station, const char* target){ + size_t length = strlen(target); + int sum = 0; + for (size_t i = 0; i < length; i++) { + sum += target[i]; + } + return sum % station->track_count; } + void add_target_capacity(struct station* station,const char* target, int capacity){ } From a17788613644585c61758c0e73f9bfb8e7fc19ed Mon Sep 17 00:00:00 2001 From: Kozar Date: Fri, 8 Nov 2024 13:28:50 +0000 Subject: [PATCH 3/4] Initializacia --- cv6/a_station.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cv6/a_station.c b/cv6/a_station.c index f483f16..d104527 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -33,6 +33,23 @@ int select_track(struct station* station, const char* target){ } void add_target_capacity(struct station* station,const char* target, int capacity){ + int track = select_track(station, target); + struct car* current = station->tracks[track]; + + while (current) { + if (strcmp(current->value, target) == 0) { + current->capacity += capacity; + return; + } + current = current->next; + } + + struct car* new_car = malloc(sizeof(struct car)); + strncpy(new_car->value, target, TARGET_SIZE - 1); + new_car->value[TARGET_SIZE - 1] = '\0'; + new_car->capacity = capacity; + new_car->next = station->tracks[track]; + station->tracks[track] = new_car; } int get_target_capacity(struct station* station,const char* target){ From 2f4bf820c1657cb30626d282fd1907d4428dd2e7 Mon Sep 17 00:00:00 2001 From: Kozar Date: Fri, 8 Nov 2024 13:58:56 +0000 Subject: [PATCH 4/4] Initializacia --- cv6/a_station.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/cv6/a_station.c b/cv6/a_station.c index d104527..da0a69b 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -52,15 +52,41 @@ void add_target_capacity(struct station* station,const char* target, int capacit station->tracks[track] = new_car; } -int get_target_capacity(struct station* station,const char* target){ +int get_target_capacity(struct station* station, const char* target) { + int track = select_track(station, target); + struct car* current = station->tracks[track]; + + while (current) { + if (strcmp(current->value, target) == 0) { + return current->capacity; + } + current = current->next; + } + return 0; } -int count_targets(struct station* station){ - return 0; +int count_targets(struct station* station) { + int count = 0; + for (int i = 0; i < station->track_count; i++) { + struct car* current = station->tracks[i]; + while (current) { + count++; + current = current->next; + } + } + return count; } -int count_capacity(struct station* station){ - return 0; +int count_capacity(struct station* station) { + int total_capacity = 0; + for (int i = 0; i < station->track_count; i++) { + struct car* current = station->tracks[i]; + while (current) { + total_capacity += current->capacity; + current = current->next; + } + } + return total_capacity; }