Initializacia
This commit is contained in:
		
							parent
							
								
									ee9e324e9f
								
							
						
					
					
						commit
						cf685571c5
					
				@ -13,13 +13,12 @@ struct tree {
 | 
			
		||||
 | 
			
		||||
struct tree* read_tree() {
 | 
			
		||||
    char buffer[SIZE];
 | 
			
		||||
    if (!fgets(buffer, SIZE, stdin)) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    while (fgets(buffer, SIZE, stdin)) {
 | 
			
		||||
        buffer[strcspn(buffer, "\n")] = 0; 
 | 
			
		||||
        
 | 
			
		||||
        if (buffer[0] == '\0') {
 | 
			
		||||
        return NULL;
 | 
			
		||||
            continue; 
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        struct tree* node = calloc(1, sizeof(struct tree));
 | 
			
		||||
@ -27,6 +26,10 @@ struct tree* read_tree() {
 | 
			
		||||
        return node;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct tree* load_tree() {
 | 
			
		||||
    struct tree* node = read_tree();
 | 
			
		||||
@ -42,13 +45,6 @@ struct tree* load_tree() {
 | 
			
		||||
            destroy_tree(node);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
    } else {  
 | 
			
		||||
        struct tree* extra = read_tree(); 
 | 
			
		||||
        if (extra) {
 | 
			
		||||
            free(extra); 
 | 
			
		||||
            destroy_tree(node);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return node;
 | 
			
		||||
@ -57,6 +53,7 @@ struct tree* load_tree() {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void run_tree(struct tree* tree) {
 | 
			
		||||
    if (!tree) {
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user