Holiday Merge Sort

Sorting Algorithms Merge Sort Coding Challenge Holiday

Holiday Merge Sort Challenge

In celebration of this day, implement a merge sort algorithm that can sort an array of integers either in ascending or descending order based on a given flag. Your task is to write a function that takes an unsorted array and a boolean flag (e.g., true for ascending and false for descending) and returns a new sorted array.

Requirements

  • Do not use built-in sorting functions.
  • Use the merge sort algorithm as the basis for your solution.
  • The function should be able to sort in ascending order if the flag is true, and in descending order if false.

Example

For input array: [34, 7, 23, 32, 5, 62] and ascending = true, the output should be [5, 7, 23, 32, 34, 62].

Happy coding and enjoy this holiday-inspired challenge!