longest increasing subsequent

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-03T14:43:08Z Indexed on 2010/05/03 14:48 UTC
Read the original article Hit count: 142

Filed under:

i have write this code is it correct? public class subsequent{

public static void main(String[] args){   

    int a[]=new int[]{0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};
    int a_b[]=new int[a.length];
         a_b[0]=1;
       int int_max=0;
        int int_index=0;
          for (int i=0;i<a.length;i++){
       for (int j=0;j<i;j++){
           if (a[i]>a[j] && a_b[i]<(a_b[j]+1)){
             a_b[i]=a_b[j]+1; }
    }       
                if (a_b[i]>int_max){
       int_max=a_b[i];
       int_index=i;
    }
    }
      int k=int_max+1;
        int list[]=new int[k];
        for (int i=int_index;i>0;i--){  if (a_b[i]==k-1){
          list[k-1]=a[i];
         k=a_b[i];
    }
    }
      for (int g=0;g<list.length;g++){
      System.out.println(list[g]);
    }        

    }
    }

© Stack Overflow or respective owner

Related posts about algorithm