Skip to content

Commit

Permalink
Rewrite next permutation while-loop into a for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Jan 16, 2023
1 parent fb29c31 commit 15f35f0
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions MoreLinq/Permutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,8 @@ void NextPermutation()
(_permutation[j], _permutation[k]) = (_permutation[k], _permutation[j]);

// move the tail of the permutation after the jth position in increasing order
var x = _permutation.Length - 1;
var y = j + 1;

while (x > y)
{
for (int x = _permutation.Length - 1, y = j + 1; x > y; x--, y++)
(_permutation[x], _permutation[y]) = (_permutation[y], _permutation[x]);
x--;
y++;
}
}

/// <summary>
Expand Down

0 comments on commit 15f35f0

Please sign in to comment.