Now we need to build out our result list. When we’re merging our lists together, we’re creating ordered lists that combine the elements of two lists.
Since we’re going to be removing the contents of each list until they’re both depleted, let’s start with a while loop!
Create a loop that will continue iterating while both
right have elements. When one of those two are empty we’ll want to move on.
Now we do our comparison! Check if the first element (index 0, remember) of
left is smaller than the first element of
left is smaller than
right, we want to add it to our result! Append
left to our
Since we’ve added it to our results we’ll want to remove it from
left.pop() to remove the first element from the left list.
left is larger than
right, we want to add
right to our result! Append
result and then pop it out of