0

Rust – Insertion Sort using Recursion and Iteration

This post is about a sorting algorithm called Insertion Sort with recursive and iterative implementations in Rust.

Recursive Insertion Sort

There are two functions for this implementation; although it is not a requirement. The first function is non-recursive and is just used to “bootstrap” the recursive function.

The other function is the recursive Insertion Sort function.

Sample usage would be:

This outputs

Iterative Insertion Sort

For this implementation, we have a single function that accepts a mutable reference to an array of i32 ‘s with any length and returns nothing.

Sample usage would be:

This outputs

Karl San Gabriel

Karl San Gabriel

Professional Software Developer