Merge Sort: still encountered errors

I still have a problem resolving the last step (step 11) of the Merge Sort task. You need a Pro account to view the below link.

One of you suggested me to apply ternary operator and I tried to code on my own since then. My code still doesn’t want to fire up correctly:

while (leftPos < left.length && rightPos < right.length) {
           merged[curIndex] (left[leftPos] < right[rightPos]) ? left[leftPos] : right[rightPos];
           int length = (left[leftPos] < right[rightPos]) ? leftPos++ : rightPos++;


Could anyone kindly point out where in this code I should fix ?

I figured I needed to refresh merge sort anyways so I went through the lesson in Java. I think I misunderstood your question when I gave the previous answer because I could not see the question and the code together. Hopefully, this makes up for it!

If you’re up for the challenge, see if you can combine the two lines in your if and else blocks into one line to make your code look a little cleaner.

I think this is referring to the following:

merged[curIndex] = left[leftPos];


merged[curIndex] = right[rightPos];

So can we make each of those into just one line each. So we will still have an if and else block but with only one line each inside of them. So the trick to doing that is to find a way to increment a variable on the fly without it affecting the current variable you are assigning.

Hopefully, this sets you in the right direction.

Thank you so much for the clarification and for taking the time to answer my question again :slight_smile: I completely misunderstood the task then!