Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class InsertionSort {
- private static ArrayList<Integer> inputArray = new ArrayList<Integer>();
- public static ArrayList<Integer> getInputArray() {
- return inputArray;
- }
- public InsertionSort(ArrayList<Integer> inputArray) {
- InsertionSort.inputArray = inputArray;
- }
- public void sortGivenArray() {
- for (int i = 1; i < inputArray.size(); i++) {
- int key = inputArray.get(i);
- for (int j = i - 1; j >= 0; j--) {
- if (key > inputArray.get(j)) {
- inputArray.set(j + 1, inputArray.get(j));
- if (j == 0) {
- inputArray.set(0, key);
- } else {
- }
- inputArray.set(j + 1, key);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement