From e62735dba4cd0cf891304bdf4562664b99a35e51 Mon Sep 17 00:00:00 2001 From: Bohdan Kapliuk Date: Sun, 3 Nov 2024 19:46:19 +0200 Subject: [PATCH] cv6 --- cv6/a_station.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cv6/a_station.c b/cv6/a_station.c index 23cba38..5684ad1 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -37,9 +37,27 @@ int select_track(struct station* station, const char* target) { return hash % station->track_count; } -void add_target_capacity(struct station* station,const char* target, int capacity){ +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 != NULL) { + if (strcmp(current->value, target) == 0) { + current->capacity += capacity; + return; + } + current = current->next; + } + + struct car* new_car = (struct car*)malloc(sizeof(struct car)); + new_car->capacity = capacity; + strncpy(new_car->value, target, SIZE - 1); + new_car->value[SIZE - 1] = '\0'; + new_car->next = station->tracks[track]; + station->tracks[track] = new_car; } + int get_target_capacity(struct station* station,const char* target){ return 0; }