From 872a1e48752810b7e435ef7b2fde90608df7077a Mon Sep 17 00:00:00 2001 From: rz694jd Date: Sun, 1 Dec 2019 13:52:57 +0100 Subject: [PATCH] Prva verzia --- a_station.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/a_station.c b/a_station.c index 931980f..7647b32 100644 --- a/a_station.c +++ b/a_station.c @@ -20,13 +20,48 @@ void destroy_station(struct station* station){ } free(station->tracks[i]); } + free(station); } int select_track(struct station* station, const char* target){ + int c; + int hash = station->capacity; + char* str = target; + while (c = *str++){ + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + + return hash; + } return 0; } void add_target_capacity(struct station* station,const char* target, int capacity){ + + int track = select_track(station,target); + struct car* start = station->tracks[track]; + if(start == NULL){ + start->value = target; + start->capacity = capacity; + start->next = NULL; + + }else{ + while(start->next != NULL){ + if(strcmp(start->value,target)==0){ + start->capacity = capacity; + } + start = start->next; + if(start->next == NULL){ + struct car* this =(struct car*)malloc(sizeof(struct car)); + this->value = target; + this->capacity = capacity; + this->next = NULL; + start->next = this; + free(this); + } + } + } + + } int get_target_capacity(struct station* station,const char* target){