Skip to content
Home
Thursday, 22 November 2012 09:33

Matlab code for Bubble Sort Featured

Written by 
  • font size decrease font size decrease font size increase font size increase font size
  • Print
  • Email
  • My Great Web page
  • Be the first to comment!
Rate this item
(1 Vote)

 

function S = bubblesort(A)
% Assume A row/column; Copy A to S
S = A;
N = length(S);
for lastcompare=N-1:-1:1
for i=1:lastcompare
   if S(i)>S(i+1)
     tmp = S(i);
     S(i) = S(i+1);
     S(i+1) = tmp;
   end
end
end

 

Read 4473 times
More in this category: « Matlab vectors - arrays

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.