91 lines
2.2 KiB
C
91 lines
2.2 KiB
C
#include "a_station.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
struct station* create_station(){
|
|
struct station* station = (struct station*)calloc(1,sizeof(struct station));
|
|
station->tracks = (struct car**)calloc(STATION_SIZE, sizeof(struct car*));
|
|
station->track_count = STATION_SIZE;
|
|
return station;
|
|
}
|
|
|
|
void destroy_station(struct station* station)
|
|
{
|
|
if (station == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//preiteruje cez kazdy jeden 'track/carar' v poli 'tracks' a
|
|
for (int i = 0; i < station->track_count, i++)
|
|
{
|
|
struct car* currentTracks = station->tracks;
|
|
while (currentTracks->next != NULL)
|
|
{
|
|
struct car* tempTrack = currentTracks;
|
|
currentTracks = currentTracks->next;
|
|
free(tempTrack);
|
|
}
|
|
}
|
|
free(station->tracks);
|
|
free(station);
|
|
}
|
|
|
|
int select_track(struct station* station, const char* target)
|
|
{
|
|
if (station == NULL)
|
|
{
|
|
station = (struct station*)calloc(1, sizeof(station));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void add_target_capacity(struct station* station,const char* target, int capacity)
|
|
{
|
|
|
|
}
|
|
|
|
int get_target_capacity(struct station* station,const char* target)
|
|
{
|
|
for (int i = 0; i < station->track_count, i++)
|
|
{
|
|
struct car* currentTracks = station->tracks[i];
|
|
while (currentTracks->next != NULL)
|
|
{
|
|
if (strcmp(currentTracks->value, target) == 0)
|
|
{
|
|
return currentTracks->capacity;
|
|
}
|
|
currentTracks = currentTracks->next;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int count_targets(struct station* station)
|
|
{
|
|
int count = 0;
|
|
for (int i = 0; i < station->track_count, i++)
|
|
{
|
|
struct car* currentTracks = station->tracks[i];
|
|
while (currentTracks->next->value != NULL && currentTracks->next != NULL)
|
|
{
|
|
count += 1;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
int count_capacity(struct station* station){
|
|
int count = 0;
|
|
//preiteruje cez vsetky instancie...
|
|
for (int i = 0; i < station->track_count, i++)
|
|
{
|
|
struct car* currentTracks = station->tracks[i];
|
|
while (currentTracks->next != NULL)
|
|
{
|
|
count += currentTracks->capacity;
|
|
}
|
|
}
|
|
return 0;
|
|
} |