- Implement the insertion sort algorithm by creating a function `insertion_sort(slice, steps)` which executes the iterations of the algorithm **up to** the number of steps indicated by the parameter `steps`. See the **Usage** for more information.
- To sort an array of size n in ascending order:
The insertion sort algorithm to sort an array of size n in ascending order:
1. Iterate from slice[1] to slice[n] over the slice.
1. Iterates from slice[1] to slice[n] over the slice.
2. Compare the current element (key) to its predecessor.
2. Compares the current element (key) to its predecessor.
3. If the key element is smaller than its predecessor, compare it to the elements before. Move the greater elements one position up to make space for the swapped element.
3. If the key element is smaller than its predecessor, compares it to the elements before. Move the greater elements one position up to make space for the swapped element.
Here is a visual example of sorting a slice step by step using the insertion sort algorithm.
@ -18,18 +18,17 @@ Here is a visual example of sorting a slice step by step using the insertion sor
**Figure 1** - Step by step execution of the algorithm insertion sort
- Implement the algorithm insertion sort by creating a function `insertion_sort(slice, steps)` that executes the iterations of the algorithm the number of steps indicated by the parameter `steps`. See the **Usage** for more information.
[paths for referring to an item in the module tree](https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html)
Create a function called `reverse_it` that takes a number and returns a string with the number backwards followed by the original number. If the number is negative you should
just add the char `-` to the beginning of the string.
Create a function called `reverse_it` that takes a number and returns a string with the number backwards followed by the original number. If the number is negative a char `-` has to be added to the beginning of the string.