Advertisement
Ocha_DSH

Untitled

May 28th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class InsertionSort {
  4.     private static ArrayList<Integer> inputArray = new ArrayList<Integer>();
  5.  
  6.     public static ArrayList<Integer> getInputArray() {
  7.         return inputArray;
  8.     }
  9.  
  10.     public InsertionSort(ArrayList<Integer> inputArray) {
  11.         InsertionSort.inputArray = inputArray;
  12.     }
  13.  
  14.     public void sortGivenArray() {
  15.         for (int i = 1; i < inputArray.size(); i++) {
  16.  
  17.             int key = inputArray.get(i);
  18.  
  19.             for (int j = i - 1; j >= 0; j--) {
  20.                 if (key > inputArray.get(j)) {
  21.  
  22.                     inputArray.set(j + 1, inputArray.get(j));
  23.  
  24.                     if (j == 0) {
  25.                         inputArray.set(0, key);
  26.                     } else {
  27.                    
  28.                     }
  29.                    
  30.                     inputArray.set(j + 1, key);
  31.                     break;
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement