push
This commit is contained in:
parent
dd425613b2
commit
876df59231
@ -3,6 +3,7 @@
|
||||
#include <string.h>
|
||||
|
||||
struct station* create_station(){
|
||||
|
||||
struct station* stanica = calloc(1, sizeof(struct station));
|
||||
stanica->tracks = calloc(STATION_SIZE, sizeof(struct car*));
|
||||
stanica->track_count = STATION_SIZE;
|
||||
@ -10,6 +11,7 @@ struct station* create_station(){
|
||||
}
|
||||
|
||||
void destroy_station(struct station* stanica){
|
||||
|
||||
for (int i = 0; i < stanica->track_count; i++){
|
||||
struct car* aktualny = stanica->tracks[i];
|
||||
while (aktualny != NULL){
|
||||
@ -20,18 +22,22 @@ void destroy_station(struct station* stanica){
|
||||
}
|
||||
free(stanica->tracks);
|
||||
free(stanica);
|
||||
|
||||
}
|
||||
|
||||
int select_track(struct station* stanica, const char* ciel){
|
||||
|
||||
unsigned long heslo = 5381;
|
||||
int znak;
|
||||
while ((znak = *ciel++)){
|
||||
heslo = ((heslo << 5) + heslo) + znak;
|
||||
}
|
||||
return heslo % stanica->track_count;
|
||||
|
||||
}
|
||||
|
||||
void add_target_capacity(struct station* stanica, const char* ciel, int kapacita){
|
||||
|
||||
int index = select_track(stanica, ciel);
|
||||
struct car* aktualny = stanica->tracks[index];
|
||||
|
||||
@ -48,9 +54,11 @@ void add_target_capacity(struct station* stanica, const char* ciel, int kapacita
|
||||
novy->capacity = kapacita;
|
||||
novy->next = stanica->tracks[index];
|
||||
stanica->tracks[index] = novy;
|
||||
|
||||
}
|
||||
|
||||
int get_target_capacity(struct station* stanica, const char* ciel){
|
||||
|
||||
int index = select_track(stanica, ciel);
|
||||
struct car* aktualny = stanica->tracks[index];
|
||||
|
||||
@ -62,9 +70,11 @@ int get_target_capacity(struct station* stanica, const char* ciel){
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int count_targets(struct station* stanica){
|
||||
|
||||
int pocet = 0;
|
||||
|
||||
for (int i = 0; i < stanica->track_count; i++){
|
||||
@ -76,9 +86,11 @@ int count_targets(struct station* stanica){
|
||||
}
|
||||
|
||||
return pocet;
|
||||
|
||||
}
|
||||
|
||||
int count_capacity(struct station* stanica){
|
||||
|
||||
int celkovo = 0;
|
||||
|
||||
for (int i = 0; i < stanica->track_count; i++){
|
||||
@ -90,4 +102,5 @@ int count_capacity(struct station* stanica){
|
||||
}
|
||||
|
||||
return celkovo;
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user