2024-10-24 17:02:50 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2024-10-24 16:53:07 +00:00
|
|
|
#ifndef TRAIN_H
|
|
|
|
#define TRAIN_H
|
|
|
|
#define SIZE 100
|
|
|
|
|
2024-10-24 17:02:50 +00:00
|
|
|
/**
|
|
|
|
* Jeden vozen vlaku
|
|
|
|
*/
|
|
|
|
struct car {
|
|
|
|
/**
|
|
|
|
* Nazov cielovej stanice
|
|
|
|
*/
|
|
|
|
char value[SIZE];
|
|
|
|
/**
|
|
|
|
* Smenik na dalsi vozen
|
|
|
|
*/
|
|
|
|
struct car* next;
|
|
|
|
};
|
|
|
|
|
2024-10-24 16:57:01 +00:00
|
|
|
|
2024-10-24 16:56:50 +00:00
|
|
|
struct car* add_car(struct car* first, const char* target) {
|
|
|
|
// Vytvorenie noveho vozna
|
|
|
|
struct car* new_car = (struct car*)malloc(sizeof(struct car));
|
|
|
|
if (new_car == NULL) {
|
|
|
|
printf("Chyba: Nepodarilo sa alokovať pamäť pre nový vozeň.\n");
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inicializacia hodnot
|
|
|
|
strncpy(new_car->value, target, SIZE);
|
|
|
|
new_car->next = NULL;
|
|
|
|
|
|
|
|
// Ak vlak neexistuje, novy vozen sa stane prvym
|
|
|
|
if (first == NULL) {
|
|
|
|
return new_car;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Najdenie posledneho vozna
|
|
|
|
struct car* temp = first;
|
|
|
|
while (temp->next != NULL) {
|
|
|
|
temp = temp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pridanie noveho vozna na koniec
|
|
|
|
temp->next = new_car;
|
|
|
|
return first;
|
2024-10-24 17:02:50 +00:00
|
|
|
}
|
2024-10-24 16:53:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Vypise vsetky vozne vo vlaku
|
|
|
|
*
|
|
|
|
* @arg smernik na prvy vozen
|
|
|
|
*/
|
|
|
|
void print_train(struct car* first);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Zrusenie vsetkych voznov vo vlaku.
|
|
|
|
* @arg smernik na prvy vozen
|
|
|
|
*/
|
|
|
|
void cancel_train(struct car* first);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Vyradenie vsetkych voznov, ktorych cielova stanica je target
|
|
|
|
*
|
|
|
|
* @arg smernik na prvy vozen
|
|
|
|
* @arg cielova stanica, ktora sa ma vyradit z vlaku.
|
|
|
|
* @return smernik na novy prvy vozen
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct car* clear_train(struct car* first,const char* target);
|
|
|
|
|
|
|
|
#endif // TRAIN_H
|