Solution Review: Sorting From 1 to n

This review provides a detailed analysis of the different ways to sort numbers from 1 to n.

First solution

This solution consists of two nested loops. The outer loop will replace the value at index i with -1. The inner loop will do the following:

  • Store the current value temporarily.
  • Set the required value at the proper index.
  • Set value for the next iteration.
  • Set the cursor for the next iteration.

Letā€™s look more through illustrations.

Get hands-on with 1400+ tech skills courses.