Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Contributor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- [VishnuThokala](https://github.com/VishnuThokala)
- [Shaurya026](https://github.com/Shaurya026)
- [Jeevesh-Joshi](https://github.com/Jeevesh-Joshi)
- [ParthPali](https://github.com/ParthPali)
45 changes: 45 additions & 0 deletions Sorting Algorithms/InsertionSorting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
public class InsertionSorting {

private int[] array;

public InsertionSorting() {
setArray();
}

public static void main(String[] args) {
InsertionSorting is = new InsertionSorting();
System.out.println("Before Sorting array is");
is.printTheArray();
is.sortTheArray();
System.out.println("After Sorting array is");
is.printTheArray();
}

private void printTheArray() {
for(int i=0; i<array.length; i++) {
System.out.print(array[i]+" ");
}
System.out.println();
}

private void sortTheArray() {
int i,j, index;

for(i=0; i<array.length; i++) {
index = array[i];
j = i - 1;

while (j > -1 && array[j] > index) {
array[j + 1] = array[j];
j--;
}

array[j + 1] = index;
}
}

private void setArray() {
int[] a = {72,21,69,38,96,77,30,19,42,55,99};
array = a;
}
}