Insertion Sort MatLab Function

[output] is an array of number which is the sorted version of [input].
518 Downloads
Updated 21 Dec 2012

View License

You can simply copy and paste this function to the folder you keep your function m-files.
Insertion Sort is of n^2 order and performs well for up to 10,000 inputs.
Examples of how you can use this function include, but aren't limited to:

1.
plot(floor(100 * rand(1,100))); hold on;
plot(insertion_sort(floor(100 * rand(1,100))),'r');

2.
a = insertion_sort([1 2 3 2 1 2 3 5 4 3 2 1 4 6 8])

I would appreciate your suggestions, further examples, comments and criticisms.

Best Regards
Mehdi

Cite As

Mehdi Goudarzi (2024). Insertion Sort MatLab Function (https://www.mathworks.com/matlabcentral/fileexchange/39528-insertion-sort-matlab-function), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Shifting and Sorting Matrices in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0