question about merge algorithm

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-26T09:24:02Z Indexed on 2010/05/26 9:31 UTC
Read the original article Hit count: 356

Filed under:
|
|

hi i have question i know that this question is somehow nonsense but let see i have code to merge two sorted array in a one sorted array here is code in java

public class Merge {


    public static  void main(String[]args){


    int a[]=new int[]{7,14,23,30,35,40};
    int b[]=new int[]{5,8,9,11,50,67,81};
    int c[]=new int[a.length+b.length];
    int al=0;
    int bl=0;
    int cl=0;
    while (al<a.length && bl<b.length)


    if (a[al]<b[bl])
      c[cl++]=a[al++];


     else  
     c[cl++]=b[bl++];


    while (al<a.length)
      c[cl++]=a[al++];

    while (bl<b.length)
     c[cl++]=b[bl++];



     for (int j=0;j<c.length;j++){
      System.out.println(c[j]);
    }


    }
    }

question is why does not work if we write here {} brackets

while (al

}

?

© Stack Overflow or respective owner

Related posts about java

Related posts about algorithm