train
This commit is contained in:
		
							parent
							
								
									aa8545df6b
								
							
						
					
					
						commit
						82a772622a
					
				
							
								
								
									
										54
									
								
								cv5/a_train.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								cv5/a_train.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,54 @@
 | 
			
		||||
#include "a_train.h"
 | 
			
		||||
 | 
			
		||||
struct car* add_car(struct car* first,const char* target) {
 | 
			
		||||
    struct car* newcar = calloc(1, sizeof(struct car));
 | 
			
		||||
    strcpy(newcar->value, target);
 | 
			
		||||
    if(first == NULL){
 | 
			
		||||
        first = newcar;
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
        struct car *this = first;
 | 
			
		||||
        while(this->next != NULL){
 | 
			
		||||
            this = this->next;         
 | 
			
		||||
        }
 | 
			
		||||
        this->next = newcar;
 | 
			
		||||
    }
 | 
			
		||||
    return first;
 | 
			
		||||
   
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void print_train(struct car* first) {
 | 
			
		||||
    struct car* this = first;
 | 
			
		||||
    if(first == NULL){
 | 
			
		||||
        printf("List is empty."); 
 | 
			
		||||
        return;   
 | 
			
		||||
    }
 | 
			
		||||
    else{
 | 
			
		||||
        while(this != NULL){
 | 
			
		||||
            printf("%s\n", this->value);
 | 
			
		||||
            this = this->next;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void cancel_train(struct car* first) {
 | 
			
		||||
    if(first != NULL){
 | 
			
		||||
        cancel_train(first->next);
 | 
			
		||||
        free(first);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct car* clear_train(struct car* first, const char* target) {
 | 
			
		||||
    struct car* this = first;
 | 
			
		||||
    while(this != NULL){
 | 
			
		||||
        if(this->value == target){
 | 
			
		||||
            return NULL;    
 | 
			
		||||
        }
 | 
			
		||||
        this = this->next;
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
    return first;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										55
									
								
								cv5/a_train.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								cv5/a_train.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,55 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user