From 876df592311b9dd3087720fcc7b70fc9a4a46140 Mon Sep 17 00:00:00 2001 From: Filip Chochol Date: Wed, 15 Apr 2026 15:50:36 +0200 Subject: [PATCH] push --- du6/a_station.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/du6/a_station.c b/du6/a_station.c index 04a699d..fe504b0 100644 --- a/du6/a_station.c +++ b/du6/a_station.c @@ -3,6 +3,7 @@ #include struct station* create_station(){ + struct station* stanica = calloc(1, sizeof(struct station)); stanica->tracks = calloc(STATION_SIZE, sizeof(struct car*)); stanica->track_count = STATION_SIZE; @@ -10,6 +11,7 @@ struct station* create_station(){ } void destroy_station(struct station* stanica){ + for (int i = 0; i < stanica->track_count; i++){ struct car* aktualny = stanica->tracks[i]; while (aktualny != NULL){ @@ -20,18 +22,22 @@ void destroy_station(struct station* stanica){ } free(stanica->tracks); free(stanica); + } int select_track(struct station* stanica, const char* ciel){ + unsigned long heslo = 5381; int znak; while ((znak = *ciel++)){ heslo = ((heslo << 5) + heslo) + znak; } return heslo % stanica->track_count; + } void add_target_capacity(struct station* stanica, const char* ciel, int kapacita){ + int index = select_track(stanica, ciel); struct car* aktualny = stanica->tracks[index]; @@ -48,9 +54,11 @@ void add_target_capacity(struct station* stanica, const char* ciel, int kapacita novy->capacity = kapacita; novy->next = stanica->tracks[index]; stanica->tracks[index] = novy; + } int get_target_capacity(struct station* stanica, const char* ciel){ + int index = select_track(stanica, ciel); struct car* aktualny = stanica->tracks[index]; @@ -62,9 +70,11 @@ int get_target_capacity(struct station* stanica, const char* ciel){ } return 0; + } int count_targets(struct station* stanica){ + int pocet = 0; for (int i = 0; i < stanica->track_count; i++){ @@ -76,9 +86,11 @@ int count_targets(struct station* stanica){ } return pocet; + } int count_capacity(struct station* stanica){ + int celkovo = 0; for (int i = 0; i < stanica->track_count; i++){ @@ -90,4 +102,5 @@ int count_capacity(struct station* stanica){ } return celkovo; + }