Question
Merge sort wont work For some reason when i go to implement it in the main method it gives me a error of The
Merge sort wont work
For some reason when i go to implement it in the main method it gives me a error of
" The method mergeSort(LinkedList) in the type ArrayReview is not applicable for the arguments (int[])"
Also when i go to return merge(mergeSort(left),mergeSort(Right) i get an error of" void methods cannot return a value".
Anything is a big help thanks
Here is the code:
LinkedList mergeSort(LinkedList merged){
if((merged== null) || (merged.size() == 1)) return merged;
else if(merged.size() == 2)
if(merged.get(0).intValue()>merged.get(1).intValue()) return merged;
else{
LM tmp = (LM)merged.get(0);
merged.set(0,merged.get(1));
merged.set(1,tmp);
}
return merged;
}
{
//Merge doesn't work for some reason as if its a void method
LinkedListLeft = new LinkedList(list.subList(0,list.size()/2));
LinkedListRight = new LinkedList(list.subList(list.size()/2,list.size()));
return merge(mergeSort(Left),mergeSort(Right));
}
LinkedList merge(LinkedListLeft,LinkedList Right)
{
int i = 0, j=0;
LinkedList merge = new LinkedList<>();
while((i
if(Left.get(i).intValue() > Right.get(j).intValue()){
merge.add(Left.get(j));
i++;
}
else{
merge.add(Right.get(j));
j++;
}
}
while(i < Left.size())
{
if(i >=Right.size())
{
merge.add(Right.get(j));
}
i++;
}
while(j < Right.size())
{
if(j>= Left.size())
{
merge.add(Left.get(i));
}
merge(Left,Right);
}
return merge;
}
public static void main(String...strings){
long now = System.nanoTime();
ArrayReview time = new ArrayReview();
for(int i = 0;i<1;i++)
{
time.printList();
}
System.out.println("Fibinacci number " + fib(10));
ArrayList C = new ArrayList<>(Arrays.asList('h','e','l','l','o'));
System.out.println(" The result of the Palidrome 'hello' is " + getPalindrome(C));
int [] merged= {54,5,33};
mergeSort(merged);
System.out.println(" Merge sort result: ");
for(int i=0;i
System.out.print(merged[i] + " ");
}
long execute = System.nanoTime() - now;
System.out.println("My program takes " + execute + " Nano seconds to run ArrayList");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started