Skip to content

Commit

Permalink
Merge pull request #16 from diabl0-NEMESIS/patch-2
Browse files Browse the repository at this point in the history
Recursive_Insertion_Sort
  • Loading branch information
Rjndrkha authored Oct 2, 2021
2 parents 01b036b + 0be0a38 commit fb1893e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions JAVA/Recursive_Insertion_Sort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


import java.util.Arrays;

public class DEMONIC
{

static void insertionSortRecursive(int arr[], int n)
{
// Base case
if (n <= 1)
return;

insertionSortRecursive( arr, n-1 );

int last = arr[n-1];
int j = n-2;

while (j >= 0 && arr[j] > last)
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = last;
}


public static void main(String[] args)
{
int arr[] = {12, 11, 13, 5, 6};

insertionSortRecursive(arr, arr.length);

System.out.println(Arrays.toString(arr));
}
}

0 comments on commit fb1893e

Please sign in to comment.