Skip to content

Instantly share code, notes, and snippets.

@Vimalraj571
Created November 5, 2021 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vimalraj571/a5e98099eafeb500848eee5560f22ded to your computer and use it in GitHub Desktop.
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.....
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