2
This commit is contained in:
parent
5b78da9114
commit
67da704635
@ -25,11 +25,11 @@ void destroy_station(struct station* station) {
|
||||
}
|
||||
|
||||
int select_track(struct station* station, const char* target) {
|
||||
int hash = 0;
|
||||
unsigned int hash = 0;
|
||||
for (int i = 0; target[i] != '\0'; i++) {
|
||||
hash = (hash * 31 + target[i]) % station->track_count;
|
||||
hash = (hash * 31 + target[i]);
|
||||
}
|
||||
return hash;
|
||||
return hash % station->track_count;
|
||||
}
|
||||
|
||||
void add_target_capacity(struct station* station, const char* target, int capacity) {
|
||||
@ -46,6 +46,7 @@ void add_target_capacity(struct station* station, const char* target, int capaci
|
||||
|
||||
struct car* new_car = malloc(sizeof(struct car));
|
||||
strncpy(new_car->value, target, TARGET_SIZE);
|
||||
new_car->value[TARGET_SIZE - 1] = '\0'; // Гарантия завершения строки
|
||||
new_car->capacity = capacity;
|
||||
new_car->next = station->tracks[index];
|
||||
station->tracks[index] = new_car;
|
||||
|
Loading…
Reference in New Issue
Block a user