Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "sort.h"
  3. #define SUCCESS 0
  4.  
  5. int sort(int *a, int *N)
  6. {
  7.     int tmp;
  8.     int min = a[0];
  9.     int max = a[0];
  10.     int indmax;
  11.     int indmin;
  12.    
  13.     for (int i = 0; i < *N; i++)
  14.     {
  15.         if (a[i] <= min)
  16.         {
  17.             min = a[i];
  18.             indmin = i;
  19.         }
  20.         if (a[i] >= max)
  21.         {
  22.             max = a[i];
  23.             indmax = i;
  24.         }
  25.     }
  26.  
  27.     if (indmin > indmax)
  28.     {
  29.         tmp = indmin;
  30.         indmin = indmax;
  31.         indmax = tmp;
  32.     }
  33.     for (int i = indmin; i < indmax; i++)
  34.     {
  35.         //printf("i = %d\n", i);
  36.         for (int j = indmin; j < indmax + indmin - i - 1; j++)
  37.         {
  38.             //printf("j = %d\n", j);
  39.             if (a[j] > a[j+1])
  40.             {
  41.                 tmp = a[j];
  42.                 a[j] = a[j+1];
  43.                 a[j+1] = tmp;
  44.             }
  45.         }
  46.     }
  47.     return SUCCESS;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement