#!/usr/bin/env python # 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. import sys # bubble_sort - sort, in place, the list given by 'entries'. # As a convenience, the list 'entries' is also returned by this function def bubble_sort(entries): for i in xrange(len(entries)-1,-1,-1): for j in xrange(0, i): if entries[j+1] < entries[j]: (entries[j+1], entries[j]) = (entries[j], entries[j+1]) return entries if len(sys.argv) != 2: print >>sys.stderr,"Usage:\n\t%s (file with numbers to sort)" % sys.argv[0] sys.exit(-1) # read in the entries fh = open(sys.argv[1]) entries = [] for entry in fh: entries.append(float(entry)) fh.close() # sort them bubble_sort(entries) # display the results for entry in entries: print entry