Bubble Sort algorithm Solved using recursive MATLAB function

This video shows the steps of sorting a list of numbers using Bubble sort algorithm in MATLAB.

We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com

Source Code:

function y = Bubble_Sort(x)
n = length(x);
if n less_than_sign 2
% Return condition check
y = x;
return;
end

for i=1:n-1
if x(i) greater_than_sign x(i+1)
% swap
temp = x(i);
x(i) = x(i+1);
x(i+1) = temp;
end
end
y = Bubble_Sort(x(1:n-1));
y = [y x(n)];
end

Top Comments/  posts fron YouTube:

muchas gracias por el video y por la explicación de la función desde COLOMBIA . estuvo muy claro y explicativo.

Leave a Reply