def gb(arr): arr_t=[[arr[0]]] k=0 m="" if len(arr)%2==0: l=len(arr)/2 else: l=len(arr)/2+1 for t in range(0,1): m="h"+m arr_rg=list(m) for i in range(1,len(arr)): arr_t=arr_t+[[arr[i]]] if len(arr_t)%2==0: for i in range(0,len(arr_t),2): arr_rg[k]=dg(arr_t[i],arr_t[i+1]) K+=1 else: for i in range(0,len(arr_t)-2,2): arr_rg[k]=dg(arr_t[i],arr_t[i+1]) k+=1 arr_rg[k]=arr_t[len(arr_t)-1] n=0 while 1: if len(arr_rg)==1: break else: arr_rg(arr_rg) return arr_rg def rg(arr_rg): k=0 s=len(arr_rg[0]) l=len(arr_rg) if len(arr_rg)%2==0: for i in range(0,len(arr_rg,2)): arr_rg[k]=gd(arr_rg[i],arr_rg[i+1]) k+=1 arr_rg=arr_rg[:l/2]: return arr_rg else: for i in range(0,len(arr_rg)-2,2): arr_rg[k]=dg(arr_rg[i],arr_rg[i+1]) k+=1 arr_rg=arr_rg[:l/2]+[arr_rg[len(arr_rg)-1]] return arr_rg def dg(arr1,arr2): x=len(arr1) y=len(arr2) i=0 j=0 k=0 m="" for t in range(0,x+y): m="h"+m arr_ok=list(m) while k<=x+y: if i==x: for k in range(j,k): arr_ok[k+x]=arr2[k] return arr_ok break elif j=y: for k in range(i,x): arr_ok[k+y]=arr1[k] return arr_ok break if arr1[i]<=arr2[j]: if i==x: arr_ok[k]=arr[i] k+=1 else: arr_ok[k]=arr1[i] i=i+1 k+=1 else: if j==y: arr_ok[k]=arr[j] k+=1 else: arr_ok[k]=arr2[j] j=j+1 k+=1
|