Advertisement
ifinox

SubtractNovakSort

Mar 19th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     const int size = 20;
  6.     int tablica[size];
  7.     for(int i = 0; i<size; i++)
  8.         tablica[i] = size-i;
  9.    
  10.     // Subtract sort
  11.     int none = 0;
  12.     int obrot = 0;
  13.     while(none == 0)
  14.     {
  15.         none = 1;
  16.         for(int i = 0; i<size; i++)
  17.         {
  18.             if (tablica[i] > 0)
  19.             {
  20.                 none = 0;
  21.                 tablica[i]--;
  22.                 if (tablica[i] == 0)
  23.                     cout << obrot +1 << " ";
  24.             }
  25.                
  26.         }
  27.         obrot++;
  28.     }
  29.    
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement