This commit is contained in:
Radovan Kofira 2020-11-05 21:16:49 +01:00
parent 85a3bd531d
commit b16d302b96

View File

@ -27,17 +27,29 @@ struct car* add_car(struct car* first,const char* target) {
}
void print_train(struct car* first) {
//struct car* this=first;
// while(this->next!=NULL){
// printf("%s",this->value);
// this=this->next;
//}
struct car* this=first;
while(this->next!=NULL){
printf("%s",this->value);
this=this->next;
}
}
void cancel_train(struct car* first) {
if(first!=NULL){
first->next=first;
free(first->next);
cancel_train(first);
}
}
//Funkcia na zrušenie spojkového zoznamu môže pracovať rekurzívne:
//Ak je zoznam prázdny, potom rušenie končí.
//Inak sa najprv uvoľní ďalší prvok next rekurzívnym volaním.
//Na konci sa uvoľní aktuálny prvok.
//Nezabudnite, že ak pamäť uvoľníte pamäť, tak s ňou už nemôžete pracovať.
struct car* clear_train(struct car* first, const char* target) {
struct car* prev = first;
//Už sme si istí, že prev a prev->next nie sú NULL