Advertisement
hadiuzzaman65

selection sort

Apr 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. void selection(int arr[],int n)
  5. {
  6.     for(int i=0; i<n; i++)
  7.     {
  8.         int small=i ;
  9.         for(int j=i+1; j<n+1; j++)
  10.         {
  11.             if(arr[j]<arr[small])
  12.                 small=j;
  13.         }
  14.         if(small !=i)
  15.         {
  16.             int temp=arr[i];
  17.             arr[i]=arr[small];
  18.             arr[small]=temp;
  19.         }
  20.  
  21.     }
  22.     for(int i=0; i<n; i++)
  23.     {
  24.         cout<<arr[i]<<endl;
  25.     }
  26. }
  27. int main()
  28. {
  29.    int arr[]={1,6,3,9,13,7,19};
  30.    selection(arr,7);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement