#!/usr/bin/octave -qf % Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) % % This work is licensed under the Creative Commons Attribution-NonCommercial- % ShareAlike License. To view a copy of this license, visit % http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to % Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, % 94105, USA. % bubble_sort(entries) - sorts the vector 'entries' and returns the results function entries=bubble_sort(entries) for i=size(entries,1):-1:1, for j=1:i-1, if entries(j+1) < entries(j), swp = entries(j+1); entries(j+1) = entries(j); entries(j) = swp; endif endfor endfor endfunction if nargin != 1, fprintf(stderr, "Usage:\n\t%s (file with numbers to sort)\n", program_name); exit(-1); endif % read in the results fh = fopen(argv{1}); entries = fscanf(fh, "%f\n"); fclose(fh); % sort them entries=bubble_sort(entries); % display the results disp(entries);