java - binary insertion sort algorithm -


I have tried to implement the binary entry sorting algorithm.

Here is my code:

{pre> public class binary_injection {public static zero type (int a [], int n) {for (int i = 0; i & lt ; N; ++ i) {int temp = a [i]; Int left = 0; Int correct = i; While (left & lt; right) {int middle = (left + right) / 2; If (float> = one [middle]) = left = right + 1; And right = middle; } (Int j = i; j & gt; left; -j) {swap (a, j-1, j); }}} Public static zero main (string [] args) {int a [] = new int [] {12,10,34,23,9,7,8,5,6}; Type (a, a.length); For (int i = 0; i & lt; a.length; i ++) {System.out.println (A [ii]); }} Public static zero swap (int a [], int i, int j) {int k = a [i]; A [i] = a [ja]; A [j] = k; }} And

The first thing that stands is here:

  while (left & lt; right) {int Middle = (left) + true) / 2; If (float> = one [middle]) = left = right + 1; And right = middle;  

You want left = middle + 1 .

This code works with that change for me.


Comments