Guest User

Untitled

a guest
Oct 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. //iterates to the next permutation lexicographically
  2. NPlayersBijection NPlayersBijection::operator++()
  3. {
  4.     for(int e=playersPartition1.size()-1; e >= 0; e--)
  5.     {
  6.         for(int k=playersPartition1[e].size()-2; k>=0; k--)
  7.         {
  8.             if(playersBijection[playersPartition1[e][k] ] < playersBijection[playersPartition1[e][k+1] ])
  9.             {
  10.                 for(int l=playersPartition1[e].size()-1; l>k; l--)
  11.                 {
  12.                     if(playersBijection[playersPartition1[e][k] ] < playersBijection[playersPartition1[e][l] ])
  13.                     {
  14.                         swap(playersBijection[playersPartition1[e][k] ], playersBijection[playersPartition1[e][l] ]);
  15.  
  16.                         for(int i=k+1, j=playersPartition1[e].size()-1; i<=j; i++, j--)
  17.                             swap(playersBijection[playersPartition1[e][i] ], playersBijection[playersPartition1[e][j] ]);
  18.  
  19.                         if(isIdentity(e))
  20.                             break;
  21.                         else
  22.                             return *this;
  23.                     }
  24.                 }
  25.                 break;
  26.             }
  27.         }
  28.  
  29.         //resets the current partition to the identity
  30.         for(int p=0; p<(int)playersPartition1[e].size(); p++)
  31.             playersBijection[playersPartition1[e][p] ] = identity[playersPartition1[e][p] ];
  32.     }
  33.  
  34.     return *this;
  35. };
Add Comment
Please, Sign In to add comment