Example #1
0
void TreeDictionary::printIndented(TreeNode * node, int level) {
  for (int i=0; i < level; i++) printf("  ");
  if (node == NULL) {
    printf("NULL\n");
    return;
	}
	printf("%s:%d\n", node->_key, node->_data);
  printIndented(node->_left,level+1);
  printIndented(node->_right,level+1);
}
void 
TreeDictionary::printIndented(TreeNode * node, int level) {
	if(node == NULL) 
	{
	printf("NULL\n");
	return;
	}
		
	//print tab
	int n = 0;
	for(;n<level;n++){
		printf("  ");
	}

        std::cout<<node->_key<<":"<<node->_data<<std::endl;	
	
	if(node->_left == NULL){
         	int j = 0;
		for(;j<level+1;j++){
                	printf("  ");
        	}
		printf("NULL\n");
				
        }
        else{
           
		printIndented(node->_left,level+1);
        }

        
       if(node->_right == NULL){
               int k = 0;
		for(;k<level+1;k++){
                        printf("  ");
                }	
		printf("NULL\n");	

        }
        else{
                printIndented(node->_right,level+1);
        }

}
Example #3
0
int are_equals(char * file_path1, char * file_path2) {

    str_file * file1;
    str_file * file2;
    file1 = (str_file *) malloc(sizeof(str_file));
    file2 = (str_file *) malloc(sizeof(str_file));

    // Copio i due percorsi passati per parametro nel campo path delle rispettive strutture precedentemente dichiarate..
    file1->path = (char*)malloc(sizeof(char) * strlen(file_path1));
    strcpy(file1->path, file_path1);
    file2->path = (char*)malloc(sizeof(char) * strlen(file_path2));
    strcpy(file2->path, file_path2);

    if ((file1->file = fopen(file1->path,"rb")) == NULL)  {
        // Impossibile aprire path1
        perror(file1->path);
        exit(EXIT_FAILURE);
    }
    else if ((file2->file = fopen(file2->path,"rb")) == NULL)  {
        // Impossibile aprire path2
        perror(file2->path);
        exit(EXIT_FAILURE);
    }
    else
    {
        // Return value
        int ris = 0;

        // Obtain file1 dimension in bytes
        fseek(file1->file, 0, SEEK_END);
        file1->size = ftell(file1->file);
        file1->line = (char *) malloc(file1->size);
        fseek(file1->file, 0, SEEK_SET);  // Return to the top of the file

        // Read the entire file1 and file2
        //file1->read = fread(file1->line, file1->size, 1, file1->file);

        //fclose(file1->file);
        //free(file1);

        // Obtain file2 dimension in bytes
        fseek(file2->file, 0, SEEK_END);
        file2->size = ftell(file2->file);
        file2->line = (char *) malloc(file2->size);
        fseek(file2->file, 0, SEEK_SET);  // Return to the top of the file

        //file2->read = fread(file2->line, file2->size, 1, file2->file);

        char buf_file1[128];
        char buf_file2[128];

        // Muovo i buffer utilizzati per il controllo in maniera parallela
        while(fgets(buf_file1, 128, file1->file) != NULL && fgets(buf_file2, 128, file2->file) && !ris) {
            if(strcmp(buf_file1, buf_file2) != 0) {
                ris = 1;
            }
        }

        // SarĂ² arrivato alla fine dei uno dei due files..
        // Stampo la differenza solo di uno rispetto all'altro..
        while(fgets(buf_file1, 128, file1->file) != NULL && !ris) {
            ris = 1;
        }
        while(fgets(buf_file2, 128, file2->file) != NULL && !ris) {
            ris = 1;
        }

        // Confronta se i files sono identici
        //ris = strcmp(file1->line , file2->line) == 0 ? 1 : 0; /* 0 */
        
        if( ris == 0) {
            printIndented("I files sono uguali!", 1);
        } else {
            printIndented("I files sono diversi!", 1);
        }

        fclose(file1->file);
        free(file1);
        fclose(file2->file);
        free(file2);

        // Ritorna il risultato del confronto: 0 se i files sono identici.
        return ris;
    }
}
void 
TreeDictionary::printIndented(){
	printIndented(_root,0);
}