Fixing adding

This commit is contained in:
Anton Dolozin 2025-11-05 11:28:52 +01:00
parent 44c9a7a188
commit 39b29d3131

View File

@ -58,42 +58,37 @@ void add_target_capacity(struct station* station,const char* target, int capacit
int get_target_capacity(struct station* station,const char* target){ int get_target_capacity(struct station* station,const char* target){
struct car* ptr = *station->tracks; int res = select_track(station, target);
while (ptr) struct car** ptr = &station->tracks[res];
{ if(strcmp(ptr->value, target) == 0){ struct car* head = *ptr;
return ptr->capacity; if(head){
return head->capacity;
}
ptr = ptr->next;
} }
return 0; return 0;
} }
int count_targets(struct station* station){ int count_targets(struct station* station){
int count = 0; if(station == NULL || station->tracks == NULL){
if(*station->tracks == NULL || station == NULL){
return 0; return 0;
} }
struct car* ptr = *station->tracks; return 0;
while (ptr)
{
count++;
ptr = ptr->next;
}
return count;
} }
int count_capacity(struct station* station){ int count_capacity(struct station* station){
int res = 0; if(station == NULL || station->tracks == NULL){
struct car* ptr = *station->tracks; return 0;
while (ptr){ }
res += ptr->capacity; int total = 0;
ptr = ptr->next; for(int i = 0; i<station->track_count; i++){
struct car* ptr = station->tracks[i];
while(ptr){
total += ptr->capacity;
ptr = ptr->next;
}
} }
return res; return total;
} }