Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include<string>
  3. #include <fstream>
  4. #include<string>
  5. #include<sstream>
  6. using namespace std;
  7. ofstream out("C:\\Users\\Darkman\\Downloads\\output.txt");
  8. selectionsort(int a[],int n)
  9. {
  10.     int k=0;
  11.     int t;
  12.     for(int i=0; i<n-1; i++)
  13.     {
  14.         t=i;
  15.         for(int j=i+1; j<n; j++)
  16.         {
  17.             if(a[t]>a[j])
  18.             {
  19.                 k=k+(j-t);
  20.                 t=j;
  21.             }
  22.         }
  23.         int temp=a[i];
  24.         a[i]=a[t];
  25.         a[t]=temp;
  26.     }
  27.     cout<<k<<endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement