diff --git a/du6/a_station.c b/du6/a_station.c index b896a98..581f21a 100644 --- a/du6/a_station.c +++ b/du6/a_station.c @@ -42,7 +42,32 @@ int select_track(struct station* station, const char* target) void add_target_capacity(struct station* station,const char* target, int capacity) { - + //helper lok. premeny + int i = select_track(station, target); + struct car* current = station->tracks[i]; + int lastPosIndex = TARGET_SIZE - 1; //index s poziciou null terminatora + + //iterovnie cez vsetky tracky + //Pocas iteracie porovna pole s cielovou stanicou pre aktualny smernik/pointer (current->value) versus vstupny argument 'target' + while (current != NULL) + { + if (strcmp(current->value, target)) + { + current->capacity += capacity; + return; + } + current = current->next; + } + + //Poistka -> ak neexistuje novy zaznam, vyvtori ho + struct car* newCar = malloc(sizeof(struct car)); + strncpy(newCar->value, target, lastPosIndex); + new_car->value[lastPosIndex] = '\0'; //null terminovanie.. + new_car->capacity = capacity; + + //vlozi na zaciatok tracku + new_car->next = station->tracks[index]; + station->tracks[index] = new_car; } int get_target_capacity(struct station* station,const char* target) @@ -87,5 +112,5 @@ int count_capacity(struct station* station){ count += currentTracks->capacity; } } - return 0; + return count; } \ No newline at end of file