% Script for a bubble sort of a vector.
% You should never actually use this because it is the worst way
% to do this.
n = 6;
disp('Original Vector')
x = rand(n,1) % Generate a column vector of n random values
% Loop over n-1 minimum searches
for i = 1:n-1
%
% x(i) holds the current smallest person for this value of i
% Do the minimum search for this value of i
for j = i+1:n
% Test if the the current person in the list is smaller than x(i).
% Swap x(j) and x(i) if they are
if(x(j) < x(i))
temp = x(i);
x(i) = x(j);
x(j) = temp;
end
end
end
disp('Sorted Vector')
x