import sys from time import clock from array import array import re def bucket_sort(data): global buckets buckets = [[] for x in range(50)] #list of empty buckets for item in data: buckets[item /20000].append(item) for bucket in buckets: bucket.sort() i = 0 for bucket in buckets: for item in bucket: data[i] = item i += 1 def main(): start = clock() fin=open("in10_7.txt","r") fout=open("out_27_10b_7.txt","w") a = array('i') global buckets k=0 lc=0 for x in fin: if (lc%2!=0): a=[] for y in x.split(", "): y=y.strip(" ") a.append(int(y)) bucket_sort(a) l=[] for i in range(0,len(a)): l.append(str(a[i])) fout.write("Sorted Set"+str(k+1)+":\n") fout.write(", ".join(l)) fout.write("\n\n") k=k+1 lc=lc+1 end = clock() time= end - start fout.write("\n Total execuion time ="+ str(time)+ " seconds") m=sys.getsizeof(a)+sys.getsizeof(x)+sys.getsizeof(y)+sys.getsizeof(lc)+sys.getsizeof(buckets)+sys.getsizeof(l)+sys.getsizeof(fin)+sys.getsizeof(fout) fout.write("\n Memory used= "+str(m)+" bytes") fin.close() fout.close() main()