Update 'cv7/a_station.c'
This commit is contained in:
parent
8ee8f39555
commit
0799f19e86
@ -33,21 +33,23 @@ int select_track(struct station* station, const char* target){
|
||||
}
|
||||
|
||||
void add_target_capacity(struct station* station,const char* target, int capacity){
|
||||
int track = select_track(station, target);
|
||||
struct car* new_car = (struct car*)malloc(sizeof(struct car));
|
||||
|
||||
strncpy(new_car->value, target, TARGET_SIZE);
|
||||
new_car->capacity = capacity;
|
||||
new_car->next = NULL;
|
||||
int track = select_track(station, target);
|
||||
struct car* current_car = station->tracks[track];
|
||||
|
||||
if (station->tracks[track] == NULL) {
|
||||
station->tracks[track] = new_car;
|
||||
} else {
|
||||
new_car->next = station->tracks[track];
|
||||
station->tracks[track] = new_car;
|
||||
while (current_car != NULL) {
|
||||
if (strcmp(current_car->value, target) == 0) {
|
||||
current_car->capacity += capacity;
|
||||
return;
|
||||
}
|
||||
current_car = current_car->next;
|
||||
}
|
||||
}
|
||||
|
||||
struct car* new_car = (struct car*)malloc(sizeof(struct car));
|
||||
strncpy(new_car->value, target, TARGET_SIZE);
|
||||
new_car->capacity = capacity;
|
||||
new_car->next = station->tracks[track];
|
||||
station->tracks[track] = new_car;
|
||||
}
|
||||
|
||||
int get_target_capacity(struct station* station,const char* target){
|
||||
int track = select_track(station, target);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user