Boo

mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
1
Indexable
Never
x = ["1.11", "2.0.0", "1.2", "2", "0.1", "1.2.1", "1.1.1", "2.0"]

def isV1greaterThanV2(v1, v2):
    v1_list = [int(x) for x in v1.split('.')]
    v2_list = [int(x) for x in v2.split('.')]
    len1 = len(v1_list)
    len2 = len(v2_list)
    
    mylen = len2
    flag = True
    
    if(len1<=len2):
        flag = False
        mylen = len1

    for i in range(mylen):
      if v1_list[i]>v2_list[i]:
          return True
      elif v1_list[i]<v2_list[i]:
          return False
    return flag

def bubbleSort(arr):
    n = len(arr)
    # Traverse through all array elements
    for i in range(n-1):
    # range(n) also work but outer loop will repeat one time more than needed.
        # Last i elements are already in place
        for j in range(0, n-i-1):
            # traverse the array from 0 to n-i-1
            # Swap if the element found is greater
            # than the next element
            if isV1greaterThanV2(arr[j],arr[j + 1]):
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
 
# Driver code to test above
arr = [64, 34, 25, 12, 22, 11, 90]
 
bubbleSort(x)
print(x)