Created
March 16, 2023 05:45
-
-
Save VallarasuS/6a7c9efed9a6ef53c71e196fbfe416fb to your computer and use it in GitHub Desktop.
Insertion Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public void insertionSort(int[] numbsers) { | |
for(int i = 1; i < numbsers.length; i++) { | |
int item = numbsers[i]; | |
int j = i - 1; | |
while (j >= 0 && item < numbsers[j]) { | |
numbsers[j + 1] = numbsers[j]; | |
j--; | |
} | |
numbsers[j + 1] = item; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment