from time import clock import sys ifile=open('in10_1.txt','r') ofile=open('out_21_10_1b.txt','w') begin=clock() ifile.readline() n=5 swap=0 comp=0 for setNum in range(1,n+1): num=[] num=ifile.readline().split(",") num[0]=num[0].lstrip("Set"+str(setNum)+":") ifile.readline() j=0 while(jint(num[ma]): ma=mi mi=k comp+=1 elif int(num[k])>int(num[ma]): ma=k comp+=1 nmi=int(num[mi]) nma=int(num[ma]) if j==ma: num[mi]=num[len(num)-j-1] num[len(num)-j-1]=nmi num[ma]=num[len(num)-j-1] num[len(num)-j-1]=nma swap+=2 comp+=2 j=j+1 continue elif k==mi: num[ma]=num[j] num[j]=nma num[mi]=num[j] num[j]=nmi swap+=2 comp+=1 j+=1 continue elif j!=mi or k!=ma : if j != mi : num[mi]=num[j] num[j]=nmi swap+=1 if k != ma : num[ma]=num[k] num[k]=nma swap+=1 comp+=1 j+=1 continue ofile.write("Set"+str(setNum)+":\n") for i in range(0,len(num)-1): ofile.write(str(int(num[i]))+",") ofile.write(str(int(num[len(num)-1]))+"\n") ofile.write("\n time = "+str(clock()-begin)) ofile.write("\ncomparison= "+str(comp)) ofile.write("\nswaps "+str(swap)) ofile.write("\n memory ="+str(sys.getsizeof(ifile) + sys.getsizeof(ofile)+ sys.getsizeof(begin)+ sys.getsizeof(num)+ sys.getsizeof(swap) + sys.getsizeof(comp)+sys.getsizeof(mi))) ifile.close() ofile.close()