This commit is contained in:
Deinerovych 2024-10-24 18:25:36 +02:00
parent 38d4e6a15c
commit 331f64642e
3 changed files with 92 additions and 0 deletions

18
cv4/Makefile Normal file
View File

@ -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)

51
cv4/a_train.h Normal file
View File

@ -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

23
cv4/main.c Normal file
View File

@ -0,0 +1,23 @@
#include "a_train.h"
#include <stdio.h>
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;
}