SHARE
TWEET

Sort vstavkami

allekco Oct 17th, 2019 17 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <stddef.h>
  7.  
  8.  
  9. int main (void) {
  10.     int N, i, ii, k, j;
  11.     scanf ("%d", &N);
  12.     int A[N];
  13.     float random;
  14.     srand(time(NULL)); 
  15.    
  16.     for (i=0; i<N; i++){
  17.         random = rand();
  18.         random = (random / RAND_MAX)*10;
  19.         A[i] = random;
  20.        
  21.     //scanf ("%d", &A[i]);
  22.     }
  23.                  
  24.     clock_t start = clock ( ) ;
  25.    
  26.     for (j = 0; j <= N; j++){
  27.         i = 1;
  28.         while (i < N){
  29.             if (A[i] >= A[i-1]){
  30.                 i++;
  31.             }
  32.             else { 
  33.                 while (A[i] < A[i-1]){
  34.                 ii = A[i-1];
  35.                 A[i-1] = A[i];
  36.                 A[i] = ii;
  37.                 i--;
  38.                 }  
  39.                 i = N; 
  40.             }          
  41.         }
  42.     }
  43.    
  44.     clock_t end= clock ( ) ;
  45.     float seconds = ( float ) ( end - start ) / CLOCKS_PER_SEC;
  46.  
  47.     for (i = 0; i< N; i++){
  48.         printf ("%d ", A[i]);
  49.     }
  50.  
  51.     printf (" \n");
  52.     printf ("%f ", seconds);
  53.    
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top