Implement insertion sort from scratch.
Given an array of integers nums, sort it in ascending order using the insertion sort algorithm and return the sorted array.
Insertion sort works by building a sorted portion of the array one element at a time. For each element, it finds the correct position in the already-sorted portion and inserts it there by shifting elements to the right.
Do not use any built-in sort functions.
nums = [5, 2, 4, 6, 1, 3][1, 2, 3, 4, 5, 6]nums = [3, 1, 2][1, 2, 3]nums = [1][1]1 <= nums.length <= 1000-10^4 <= nums[i] <= 10^4You must implement insertion sort (do not use built-in sort)Run your code to see results
Use Cmd+Enter to run