1. Си / Говнокод #25612

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    namespace belugina
    {
    void Simple_Merging_Sort (char *name){ 
    	 int a1, a2, k, i, j, kol, tmp;  
    	FILE *f, *f1, *f2;  
    	kol = 0;  
    	if ( (f = fopen(name,"r")) == NULL )    
    		printf("\nИсходный файл не может быть прочитан...");  
    	else {    while ( !feof(f) ) {      
    		fscanf(f,"%d",&a1);      
    		kol++;    
    		}   
    	 fclose(f);  
    	} 
    k = 1;  
    while ( k < kol ){ 
    	f = fopen(name,"r");    
    	f1 = fopen("smsort_1","w");    
    	f2 = fopen("smsort_2","w");   
    	if ( !feof(f) ) fscanf(f,"%d",&a1);    
    	while ( !feof(f) ){     
    		 for ( i = 0; i < k && !feof(f) ; i++ ){        
    			fprintf(f1,"%d ",a1); fscanf(f,"%d",&a1); }      
    		for ( j = 0; j < k && !feof(f) ; j++ ){        
    			fprintf(f2,"%d ",a1);  fscanf(f,"%d",&a1);}   
    	 }   
    	 fclose(f2);    fclose(f1);    fclose(f); 
    f = fopen(name,"w");   f1 = fopen("smsort_1","r");    
    	f2 = fopen("smsort_2","r");    
    	if ( !feof(f1) ) fscanf(f1,"%d",&a1);   
    	if ( !feof(f2) ) fscanf(f2,"%d",&a2);    
    	while ( !feof(f1) && !feof(f2) ){     
    	 	i = 0;      j = 0;     
    	 	while ( i < k && j < k && !feof(f1) && !feof(f2) ) {        
    			if ( a1 < a2 ) {          
    			fprintf(f,"%d ",a1); fscanf(f1,"%d",&a1);i++;}        
    			else {          
    			fprintf(f,"%d ",a2);fscanf(f2,"%d",&a2); j++;}      
    	   	} 
    while ( i < k && !feof(f1) ) {        
    		     fprintf(f,"%d ",a1);  fscanf(f1,"%d",&a1); i++;}      
    		while ( j < k && !feof(f2) ) {        
    		     fprintf(f,"%d ",a2);   fscanf(f2,"%d",&a2);  j++;}   
     	 }    
    	while ( !feof(f1) ) {      
    		fprintf(f,"%d ",a1);      fscanf(f1,"%d",&a1);    }    
    	while ( !feof(f2) ) {      
    		fprintf(f,"%d ",a2);      fscanf(f2,"%d",&a2);    }   
    	fclose(f2);    fclose(f1);    fclose(f);    k *= 2;  
    	}  
    	remove("smsort_1");  remove("smsort_2");
    } 
    }

    Вектор это не динамический массив.

    Запостил: dethless, 19 Мая 2019

    Комментарии (4) RSS

    Добавить комментарий