//merging functions of two ordered arrays Public Static int[] Mergelist (intA[],intb[]) { intresult[]; if(Checksort (a) && Checksort (b))//checks if the incoming array is ordered{result=New int[a.length+B.length]; inti=0,j=0,k=0;//I: Used to mark a array J: Used to mark the B array K: Used to mark the incoming array while(I<a.length && j<b.length)if(A[i] <=B[j]) {Result[k+ +] = a[i++]; }Else{result[k+ +] = b[j++]; } /*A while loop is used to ensure that the elements in the remaining array are passed through after two arrays are compared .*/ while(I <a.length) Result[k+ +] = a[i++]; while(J <b.length) Result[k+ +] = b[j++]; returnresult; } Else{System.out.print ("Non-ordered array, not sortable!" "); return NULL; } } //checks if the array is stored sequentially Public Static BooleanChecksort (inta[]) { for(intj=i+1; j<a.length; J + +) if(A[j-1] >A[j])return false; } return true; } //Print function Public Static voidPrintintb[]) { for(inti=0; I<b.length; i++) {System.out.print (B[i]+ (i%10 ==9?) "\ n": "\ T")); } } Public Static voidMain (String args[]) {inta[]={1,2,2,3,5,6,7,7}; intb[]={1,2,4,5,8,8,9,10,11,12,12,13,14}; intc[]=Mergelist (A, b); if(c!=NULL) print (c); ElseSystem.out.println (""); }}
Algorithm-two sequential arrays merged into an ordered array