Skip to content

Commit

Permalink
refactor: Improvement in CycleSort algorithm (iluwatar#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
hammadsaedi authored Oct 14, 2023
1 parent d4fefde commit 5123af2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Inspired by [30 seconds of code](https://github.com/Chalarangelo/30-seconds-of-c
int i = 0;
while (i < n) {
int correctpos = arr[i] - 1;
if (arr[i] < n && arr[i] != arr[correctpos]) {
if (arr[i] != arr[correctpos]) {
int temp = arr[i];
arr[i] = arr[correctpos];
arr[correctpos] = temp;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/algorithm/CycleSortSnippet.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static int[] cycleSort(int[] arr) {
int i = 0;
while (i < n) {
int correctpos = arr[i] - 1;
if (arr[i] < n && arr[i] != arr[correctpos]) {
if (arr[i] != arr[correctpos]) {
int temp = arr[i];
arr[i] = arr[correctpos];
arr[correctpos] = temp;
Expand Down

0 comments on commit 5123af2

Please sign in to comment.