function Q1 tic; A=rand(100,1); B=BubbleSort(A); disp(B); toc function B=BubbleSort(A) % SORTING AN ARRAY OF NUMBERS IN AN ASCENDING ORDER USING BUBBLE SORT % Example from PiE course % Last Revised : October 18, 2010 disp('This program shows the bubble sort method') disp('to sort an array of integers into ascending order ') disp('It works by comparing and swapping until the list is sorted') disp(' ') disp('Size of given array is:') disp(length(A)) n=length(A); % making (n-1) passes bound=n+1; while(bound) last_swap=0; % comparing each number with the next and swapping for i=1:1:bound t=A(i); if(t>A(i+1)) A(1)=A(i+1); A(i+1)=t; last_swap=i; end end bound=last_swap; end%end while toc; disp(' ') disp ('Sorting finished ...') B=A; end