Created
November 5, 2021 06:36
-
-
Save Vimalraj571/a5e98099eafeb500848eee5560f22ded to your computer and use it in GitHub Desktop.
Writing the reverse from i to 0 inside the forward loop from 0 to n. Example in Insertion Sort we are using this kind of loop.....
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
public class Main { | |
public static void main(String[] args) { | |
int[] input = {6,5,3,1,8,7,2,4}; | |
int j; | |
for (int i = 1; i < input.length; i++) { | |
// From 1 to n loop with index as i | |
j = i - 1; | |
while (j >= 0) { | |
// From i to 0 with index as j | |
System.out.println(j); | |
j--; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment