Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions