Advertisement
Guest User

Untitled

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