MCPcopy Create free account
hub / github.com/apna-college/Alpha / insertionSort

Method insertionSort

2_Basic Sorting/InsertionSort.java:6–17  ·  view source on GitHub ↗
(int arr[])

Source from the content-addressed store, hash-verified

4
5public class InsertionSort {
6 public static void insertionSort(int arr[]) {
7 for(int i=1; i<arr.length; i++) {
8 int curr = arr[i];
9 int prev = i-1;
10 //to find the index where curr is to be inserted
11 while(prev >= 0 && arr[prev] > curr) {
12 arr[prev+1] = arr[prev];
13 prev--;
14 }
15 arr[prev+1] = curr;
16 }
17 }
18
19 public static void insertionSortDescending(int arr[]) {
20 for(int i=1; i<arr.length; i++) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected