简体   繁体   English

比较二维数组

[英]compare two dimensional array

How to compare two dimensional array with different size (different row and column)? 如何比较具有不同大小(不同的行和列)的二维数组?

I have two different matrix like this : kuliahprior[][] and hasil1[][] . 我有两个不同的矩阵,像这样: kuliahprior[][]hasil1[][]

I want to see if there is element of kuliahprior in hasil1 , they have different size. 我想看看是否有元素kuliahpriorhasil1 ,它们具有不同的尺寸。 I make the check process in cekKondisi() method. 我在cekKondisi()方法中进行检查过程。 And then call it in cekpriorfinal() method, by sent element of hasil1[i][j] . 然后通过hasil1[i][j]发送元素在cekpriorfinal()方法中cekpriorfinal()进行调用。 This is my code. 这是我的代码。

But they still hang.. not error just hang for unknown (sorry for my english, thankyou) 但他们仍然挂..不是错误只是挂未知(对不起我的英语,谢谢)

    public String cekKondisi(int kdbuka){
        String status = " ";
        String kd_dosen; String kdbukax[] = new String[MAX]; 
        for (int i=0; i<dosenprior.length;i++){    
             kd_dosen=dosenprior[i];
             kdbukax=peta.getKodeBuka1(kd_dosen,tahunakademik);
             for (int k=0;k<kdbukax.length;k++){
                if (kdbuka==Integer.parseInt(kuliahprior[i][k]))
                   status = slotprior[i];      
            }
        }    
        return status;
    }


    public void cekpriorfinal(){
        String status [][]=new String[15][15];
        for (int i=0;i<15;i++){
            for(int j=0;j<15;j++){
               status [i][j] = cekKondisi(hasil1[i][j]);     
            }
        }   
        for (int i=0;i<15;i++){
            for (int j=0;j<15;j++){
                if (status[i][j]==" ")
                    status[i][j]="ok";
            }
        }
        for (int i=0;i<15;i++){
             for (int j=0;j<15;j++){
                System.out.print (status[i][j]+" "); 
             }
             System.out.println();    
         }
   }

I can't spot anything that causes an infinite loop, so I would suggest to check if this line doesn't cause the hang: 我找不到引起无限循环的任何东西,所以我建议检查一下这行是否不会导致挂起:

kdbukax = peta.getKodeBuka1(kd_dosen,tahunakademik);

Make sure you are not impatient and it was still working on the result. 确保您没有耐心,并且仍在处理结果。

You might try to use a debugger and pause the application at a random point where you think it "hangs". 您可能会尝试使用调试器,并在您认为它“挂起”的任意位置暂停应用程序。 You will see at which line it currently was. 您将看到当前所在的行。 Try to solve the problem somewhere there or in that context. 尝试解决那里或那种情况下的问题。

Also, change this 另外,改变这个

String kdbukax[] = new String[MAX]; 

to this: 对此:

String kdbukax[] = null;

There is no need to create an array, since you reassign the variable here: 无需创建数组,因为您在此处重新分配了变量:

kdbukax=peta.getKodeBuka1(kd_dosen,tahunakademik);

And if MAX is really big, that might take some time to allocate an array of that size. 如果MAX确实很大,则可能需要一些时间来分配该大小的数组。 Creating an array on the heap has this complexity: O(n) . 在堆上创建数组具有以下复杂性: O(n)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM