At Westonci.ca, we make it easy for you to get the answers you need from a community of knowledgeable individuals. Connect with a community of experts ready to provide precise solutions to your questions quickly and accurately. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.
Sagot :
Using the knowledge of computational language in python we can write the code as data into smaller chunks, sort them recursively, then merge results to produce the final sorted file with all data.
Writting the code:
import java.util.*;
public class Main {
public static void merge(String data)
{
// the input is String data which holds to sorted array separated by semicolon
// split the data string based on the semicolon in the variable arr
// arr[0] represents first sorted array and arr[1] represents second one.
String arr[]=data.split(";");
if(arr[0]==null||arr[1]==null) {
System.out.println(data);
return ;
}
String sorted_result=""; // to store the sorted alhanumeric character separated by comma
String pair=""; // to store the comparision pair
int i=0,j=0;
while(i<arr[0].length()&&j<arr[1].length())
{
// we get the character denoted by first and second in a and b variable
char a=arr[0].charAt(i);
char b=arr[1].charAt(j);
if(a<b) // if the character of first array is smaller than second
{
// we are increamenting i by 2 because there is comma character available at i+1
// so for getting next character we increament by 2
// also add pair of comparision between (a,b)
sorted_result+=a+",";
pair+="("+a+","+b+") ";
i=i+2;
}
else
{
// we are increamenting i by 2 because there is comma character available at i+1
// so for getting next character we increament by 2
// also add pair of comparision between (a,b)
sorted_result+=b+",";
pair+="("+b+","+a+") ";
j=j+2;
}
}
// if there is remaining charcater in fiest array then simply copy it the sorted_result
while(i<arr[0].length())
{
char a=arr[0].charAt(i);
sorted_result+=a+",";
i+=2;
}
// if there is remaining charcater in fiest array then simply copy it the sorted_result
while(j<arr[0].length())
{
char b=arr[0].charAt(j);
sorted_result+=b+",";
j=j+2;
}
// remove the extra comma inserted at the end
sorted_result=sorted_result.substring(0, sorted_result.length()-1);
System.out.println(sorted_result);
System.out.println(pair);
}
public static void main(String[] args) {
String input1="1,4,7,8;2,3,5,6";
merge(input1);
System.out.println();
String input2="H,L,M,P,P,R,S,b,d,i,n,o,o,p,s;1,5,5,6,7,8,C,U,V,V,W,f,h,r,s";
merge(input2);
System.out.println();
String input3="B,E,E,F,J,N,O,P,U,W,D;G,J,L,N,R,S,V,X,Y";
merge(input3);
}
}
See more about JAVA at brainly.com/question/18502436
#SPJ1


We appreciate your time on our site. Don't hesitate to return whenever you have more questions or need further clarification. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.