Advertisement
Mazamin

Selection Sort

Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void selection_sort(int * v, int size){
  5.     int i, j, min;
  6.     for(i=0;i<size-1;i++){
  7.         for(j=i+1, min=i;j<size;j++)
  8.             (v[j]>=v[min])?:(min=j);
  9.         v[i]=v[i]+v[min]-(v[min]=v[i]);
  10.     }
  11. }
  12.  
  13. main(){
  14.     int array[]={5, 2, 8, 4, 9, 1, 7}, i;
  15.     selection_sort(array, 7);
  16.     for(i=0;i<(sizeof(array)/sizeof(int));i++)
  17.         printf("%d\n", array[i]);
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement