Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Binarysort {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int n = scan.nextInt();
  7.         int[] a = new int[n];
  8.         for (int i = 0; i < n; i++) {
  9.             sort(a);
  10.             out(a);
  11.         }
  12.     }
  13.             // { 1, 4, 7, 8, 10, 10, 11, 13, 245}
  14.     // { 0 , 0, 0 , 0, 0, 0, 0, 0, 0}
  15.     // { 4, 0, 0 , 0, 0, 0, 0, 0, 0}
  16.     // { 4, 10, 0, 0, 0, 0, 0, 0, 0}
  17.         public static void sort(int[] a) {
  18.         Scanner scan = new Scanner(System.in);
  19.         int l = 0;
  20.         a[l] = scan.nextInt();
  21.         int j = a.length-1;
  22.         int i = 0;
  23.         int k = (j - i) / 2;
  24.             while(k>0&&k<a.length) {
  25.                 if (a[k] > a[l]) {
  26.                     j=k;
  27.                     k=(j-1)/2;
  28.                 }else{
  29.                     i=k;
  30.                     k=(j+i)/2;
  31.                 }
  32.                 for(int z=k;z<a.length-2;z++){
  33.                     z=a[z];
  34.                     a[z+1]=z;
  35.  
  36.  
  37.                 }
  38.  
  39.             }
  40.  
  41.  
  42.  
  43.  
  44.     }
  45.     public static void out(int[] a) {
  46.         System.out.println();
  47.         for (int val : a) {
  48.             System.out.print(val);
  49.         }
  50.     }
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement