• Eheran@lemmy.world
    link
    fedilink
    English
    arrow-up
    31
    arrow-down
    1
    ·
    19 hours ago

    How does the last step sort an of the sizes? Why even have all the other steps if that one can do it all?

    • Iron Lynx@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 hours ago

      If you want to zipper two sorted lists, you compare the first element of each list, pick that first, take the next element of that list, rinse & repeat until one list runs out and then just chuck the entire rest of the other list in the remaining space, even if that’s just one element. Since your two initial lists are already sorted, you can trust the combined list to also be sorted.

    • SmoothLiquidation@lemmy.world
      link
      fedilink
      English
      arrow-up
      25
      arrow-down
      1
      ·
      19 hours ago

      When you merge two sorted lists, you only have to compare the first element of each, since you can trust that all of the other elements are bigger. All the steps before that are there to make sure that is true.