SHARE
TWEET

selection sort

Mary_99 Jan 11th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //selecton sort
  5. void selection_sort (int A[], int n)
  6. {
  7.     int k ,j , minimum_position, swap;
  8.     for (k = 0; k< n; k++)
  9.     {
  10.         minimum_position = k;
  11.         for(j = k +1; j<n; j++)
  12.         {
  13.             if(A[j]< A[minimum_position])
  14.             minimum_position = j;
  15.         }
  16.         //swap(A[k], A[minimum_position]);
  17.         swap = A[k];
  18.         A[k]= A[minimum_position];
  19.         A[minimum_position]= swap;
  20.     }
  21. }
  22.  
  23.  
  24. int main()
  25.  
  26. {
  27.     int A [100];
  28.     int k, n ,j ,minimum_position,swap;
  29.  
  30.     printf("Enter the number of elements you want to sort =   ");
  31.     scanf("%d", &n);
  32.  
  33.     for (k=0; k<n; k++)
  34.     {
  35.     printf("\nEnter the element %d:   ", k+1);
  36.     scanf("%d", &A[k]); // not put space after d :>
  37.     fflush(stdin);
  38.     }
  39.     selection_sort(A, n);
  40.  
  41.     for (k=0; k<n; k++)
  42.     {
  43.         printf("%d\n", A[k]);
  44.     }
  45.    
  46.    
  47.     return 0;
  48. }
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