function SortList = BubbleSort(List) %SortList = BubbleSort(List) %input: List = a (row or column) vector of real numbers %output: SortList = vector with same size and components as %List but sorted in increasing order SortList=List;, flag=0;, n=length(List);, count=1; while flag == 0 for i=1:n-count flag=1; if SortList(i)>SortList(i+1) SortList([i i+1])=SortList([i+1 i]);, flag=0; end end if flag == 1 %no change needed, vector is sorted return else count=count+1; end end