Write a MATLAB program that implements the Insertion Sort algorithm. Test your implementation with this set of inputs: 16.2 32.7 -0.5 4.4 21.8 -17.0 6.9 14.1 1.5.
v = input("Enter a vector of numbers: "); for i=2:length(v) for j=i:-1:2 if v(j) < v(j-1) temp = v(j); v(j) = v(j-1); v(j-1) = temp; end end end fprintf("Sorted vector is\n") disp(v)
Get Answers For Free
Most questions answered within 1 hours.