accessing an array of arrays java -


in code below have created 2 arrays, both of holding arrays.

the first array testpayloadarrayis supposed pass entire array within position of testpayloadarray.

the runtimearrayis supposed pass array within postion of array , within array populate run time value determinded method being used in.

my execution rather incorrect, admit, unsure how move forward though.

my thought that[i][j] best way this. corresponds position in first array , j corresponds position in second. if wanted populate third postion in second array in runtimearray code this, correct?

runtimearray[1][2] = endtime - starttime; 

code below:

ublic class main {  public static void main(string[] args) {     int arraylength = integer.parseint(args[0]);     int[] sorteddecending = new int[arraylength];     int j = 0;     int k = arraylength;     for(int = arraylength; > 0; i--) {         sorteddecending[j] = k;         j++;         k--;     }     j = 0;     int[] samenum = new int[arraylength];     for(int = 0; < arraylength; i++){         samenum[i] = k;     }     int[] sortedassending = new int[arraylength];     for(int = 0; < arraylength; i++){         sortedassending[i] = i;     }      int[] randomnum = new int[arraylength];     for(int = 0; < arraylength; i++){         random rand = new random();         randomnum[i] = rand.nextint(400);     }     testinterface test = new testinterface(sorteddecending, samenum, sortedassending, randomnum);     test.runtest();  }  public void runtest(){   int[][] testpayloadarray ={this.sorteddecending, this.samenum, this.sortedassending, this.randomnum};   long[][] runtimearray = {bubblesortruntime, selectionsortruntime, insertionsortruntime,   quicksortruntime, quicksort2runtime, mergesortruntime, mergesort1runtime, heapsortruntime};    for(int = 0; i<4; i++){       runbubblesort(i, runtimearray[i], testpayloadarray[i]);       runselectionsort(i, runtimearray[i], testpayloadarray[i]);       runinsertionsort(i, runtimearray[i], testpayloadarray[i]);       runquicksort(i,runtimearray[i], testpayloadarray[i]);       runquicksort2(i, runtimearray[i], testpayloadarray[i]);       runmergesort(i, runtimearray[i], testpayloadarray[i]);       runmergesort1(i,runtimearray[i], testpayloadarray[i]);       runheapsort(i, runtimearray[i], testpayloadarray[i]);   }   testreport(); 

yes runtimearray[1][2] represents 3rd position in 2nd array.

also, sorteddescending array, can have following loop

for(int = 0; < arraylength; i++){     sorteddescending[i] = arraylength - i; } 

also, if want store execution time in runtimearray can change signature of each sort methods return time , store in loop directly.

so, example loop can like

for (int = 0; < 4; i++) {   runtimearray[i][0] = runbubblesort(testpayloadarray[i]);   runtimearray[i][1] = runselectionsort(testpayloadarray[i]); } 

and methods like

private long runselectionsort(int[] ints) {    return endtime - starttime;; }  private long runbubblesort(int[] ints) {   return endtime - starttime;; } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -