diff --git a/cv4/Makefile b/cv4/Makefile new file mode 100644 index 0000000..cc615a1 --- /dev/null +++ b/cv4/Makefile @@ -0,0 +1,18 @@ +CC = gcc +CFLAGS = -Wall -g +TARGET = train + +all: $(TARGET) + +$(TARGET): main.o a_train.o + $(CC) $(CFLAGS) -o $(TARGET) main.o a_train.o + +main.o: main.c a_train.h + $(CC) $(CFLAGS) -c main.c + +a_train.o: a_train.c a_train.h + $(CC) $(CFLAGS) -c a_train.c + +clean: + rm -f *.o $(TARGET) + diff --git a/cv4/a_train.h b/cv4/a_train.h new file mode 100644 index 0000000..5982bfe --- /dev/null +++ b/cv4/a_train.h @@ -0,0 +1,51 @@ +#ifndef TRAIN_H +#define TRAIN_H +#define SIZE 100 + +/** + * Jeden vozen vlaku + */ +struct car { + /** + * Nazov cielovej stanice + */ + char value[SIZE]; + /** + * Smenik na dalsi vozen + */ + struct car* next; +}; + +/** + * Prida vozen na koniec vlaku. + * + * @arg nazov cielovej stanice, ktory sa ma priradit novemu voznu. + * @return smernik na zaciatok vlaku. + */ +struct car* add_car(struct car* first,const char* target); + + +/** + * 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 diff --git a/cv4/main.c b/cv4/main.c new file mode 100644 index 0000000..9e84f5c --- /dev/null +++ b/cv4/main.c @@ -0,0 +1,23 @@ +#include "a_train.h" +#include + +int main() { + struct car* train = NULL; + + train = add_car(train, "Bratislava"); + train = add_car(train, "Kosice"); + train = add_car(train, "Zilina"); + + printf("Vsetky stanice vo vlaku:\n"); + print_train(train); + + printf("\nVyradujeme stanicu 'Kosice':\n"); + train = clear_train(train, "Kosice"); + print_train(train); + + printf("\nZrusenie celeho vlaku:\n"); + cancel_train(train); + + return 0; +} +