Advertisement
wojtas626

[C] Array of char sort

Dec 4th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void bubbleSort(char arr[], int x)
  6. {
  7.     int i, j, bufor;
  8.     for(i = 0; i < x - 1; i++)
  9.     {
  10.         for(j = 0; j < x - 1 - i; j++)
  11.         {
  12.             if(arr[j] > arr[j + 1])
  13.             {
  14.                 bufor = arr[j];
  15.                 arr[j] = arr[j + 1];
  16.                 arr[j + 1] = bufor;
  17.             }
  18.         }
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     int n = 100;
  25.     char arr[n];
  26.     int i;
  27.     srand(time(NULL));
  28.  
  29.     for(i = 0; i < n; i++)
  30.     {
  31.         arr[i] = (rand() % 26) + 65;
  32.     }
  33.  
  34.     for(i = 0; i < n; i++)
  35.     {
  36.         printf("%c", arr[i]);
  37.     }
  38.  
  39.     printf("\n\n");
  40.     bubbleSort(arr, n);
  41.  
  42.     for(i = 0; i < n; i++)
  43.     {
  44.         printf("%c", arr[i]);
  45.     }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement