refresh
This commit is contained in:
parent
b357fe0711
commit
4492629238
@ -19,9 +19,7 @@ int select_track(struct station* s, const char* target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void add_target_capacity(struct station* s, const char* target, int capacity) {
|
void add_target_capacity(struct station* s, const char* target, int capacity) {
|
||||||
if (!s || !target) {
|
if (!s || !target) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = select_track(s, target);
|
int index = select_track(s, target);
|
||||||
struct car* current = s->tracks[index];
|
struct car* current = s->tracks[index];
|
||||||
@ -52,23 +50,23 @@ void add_target_capacity(struct station* s, const char* target, int capacity) {
|
|||||||
prev->next = new_car;
|
prev->next = new_car;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct car* find_target(struct station* s, const char* target) {
|
int get_target_capacity(struct station* s, const char* target) {
|
||||||
if (!s || !target) return NULL;
|
if (!s || !target) return 0;
|
||||||
|
|
||||||
int index = select_track(s, target);
|
int index = select_track(s, target);
|
||||||
struct car* current = s->tracks[index];
|
struct car* current = s->tracks[index];
|
||||||
|
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
if (strcmp(current->value, target) == 0) {
|
if (strcmp(current->value, target) == 0) {
|
||||||
return current;
|
return current->capacity;
|
||||||
}
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_total_targets(struct station* s) {
|
int count_targets(struct station* s) {
|
||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -82,7 +80,7 @@ int get_total_targets(struct station* s) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_total_capacity(struct station* s) {
|
int count_capacity(struct station* s) {
|
||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
@ -96,22 +94,6 @@ int get_total_capacity(struct station* s) {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_station(struct station* s) {
|
|
||||||
if (!s) return;
|
|
||||||
|
|
||||||
printf("station>>>\n");
|
|
||||||
for (int i = 0; i < s->track_count; i++) {
|
|
||||||
struct car* current = s->tracks[i];
|
|
||||||
printf("[%d]: ", i);
|
|
||||||
while (current != NULL) {
|
|
||||||
printf("%s (%d) -> ", current->value, current->capacity);
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
printf("NULL\n");
|
|
||||||
}
|
|
||||||
printf("<<<station\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_station(struct station* s) {
|
void destroy_station(struct station* s) {
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user