Insertion Sort - Part 1

  • + 0 comments

    JAVA int key = arr.get(n - 1); int j = n - 2;

        while (j >= 0 && arr.get(j) > key) {
            arr.set(j + 1, arr.get(j)); 
            j--; 
            for (int k = 0; k < arr.size(); k++) {
            System.out.print(arr.get(k) + " ");
        }
        System.out.println();
        }
    
        arr.set(j + 1, key);
    
          for(int i=0;i<arr.size();i++) {
         System.out.print(arr.get(i) + " ");
     }