Advertisement
volkovich_maksim

bubblr_sort

Sep 15th, 2016
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. long int bubble(long int array[], long int length_of_array){
  5.     int iteration, i;
  6.     for (iteration = 0; iteration < length_of_array; iteration++){
  7.         for (i = iteration; i < length_of_array-1; i++){
  8.             if (array[i] < array[i+1]){
  9.                 array[i] = array[i+1] + array[i];
  10.                 array[i+1] = array[i] - array[i+1];
  11.                 array[i] = array[i] - array[i+1];
  12.             }
  13.        
  14.         }
  15.     }
  16.     return 0;
  17. }
  18.  
  19.  
  20. int main(void){
  21.     long int length_of_array, i, number;
  22.     long int specificator = 0;
  23.  
  24.  
  25.     while (specificator != 1){
  26.         specificator = scanf("%ld", &length_of_array);
  27.     }
  28.  
  29.     long int array[length_of_array];
  30.  
  31.  
  32.     for (i = 0; specificator == 1 && i < length_of_array; i++){
  33.         specificator = scanf("%ld", &number);
  34.         array[i] = number;
  35.     }
  36.  
  37.    
  38.     if (i != length_of_array || specificator != 1)
  39.         printf("\nbad input\n");
  40.     else if (length_of_array != 1){
  41.         bubble(array, length_of_array);
  42.         }
  43.          for (i = 0; i < length_of_array; i++){
  44.             printf("%ld ", array[i]);
  45.          }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement