Update ShellSort.py
This commit is contained in:
30
ShellSort.py
30
ShellSort.py
@@ -92,18 +92,37 @@ for ob in bpy.data.objects:
|
|||||||
#sort array based on location.x
|
#sort array based on location.x
|
||||||
cubes.sort(key = lambda obj: obj.location.x)
|
cubes.sort(key = lambda obj: obj.location.x)
|
||||||
|
|
||||||
#Shell Sprt Algorithm
|
iframe=0
|
||||||
|
|
||||||
|
#Shell Sort Algorithm
|
||||||
def shellSort(arr, n):
|
def shellSort(arr, n):
|
||||||
|
|
||||||
|
global iframe
|
||||||
|
|
||||||
gap=n//2
|
gap=n//2
|
||||||
|
|
||||||
while gap>0:
|
while gap>0:
|
||||||
|
|
||||||
j=gap
|
j=gap
|
||||||
|
|
||||||
# Check the array in from left to right
|
# Check the array in from left to right
|
||||||
# Till the last possible index of j
|
# Till the last possible index of j
|
||||||
while j<n:
|
while j<n:
|
||||||
|
|
||||||
i=j-gap # This will keep help in maintain gap value
|
i=j-gap # This will keep help in maintain gap value
|
||||||
while i>=0:
|
while i>=0:
|
||||||
|
|
||||||
|
for cube in arr:
|
||||||
|
cube.keyframe_insert(data_path="location", frame= iframe)
|
||||||
|
|
||||||
|
#add 1 to comparison counter
|
||||||
|
comparisonCounter.inputs[0].default_value += 1
|
||||||
|
comparisonCounter.inputs[0].keyframe_insert(data_path='default_value', frame=iframe)
|
||||||
|
|
||||||
|
#add 2 to array counter
|
||||||
|
arrayCounter.inputs[0].default_value += 2
|
||||||
|
arrayCounter.inputs[0].keyframe_insert(data_path='default_value', frame=iframe)
|
||||||
|
|
||||||
# If value on right side is already greater than left side value
|
# If value on right side is already greater than left side value
|
||||||
# We don't do swap else we swap
|
# We don't do swap else we swap
|
||||||
if arr[i+gap].scale.z > arr[i].scale.z:
|
if arr[i+gap].scale.z > arr[i].scale.z:
|
||||||
@@ -112,8 +131,17 @@ def shellSort(arr, n):
|
|||||||
else:
|
else:
|
||||||
arr[i+gap].location.x = i
|
arr[i+gap].location.x = i
|
||||||
arr[i].location.x = i + gap
|
arr[i].location.x = i + gap
|
||||||
|
|
||||||
|
arr[i+gap].keyframe_insert(data_path="location", frame= iframe)
|
||||||
|
arr[i].keyframe_insert(data_path="location", frame= iframe)
|
||||||
|
iframe += 1
|
||||||
|
|
||||||
arr[i+gap],arr[i] = arr[i],arr[i+gap]
|
arr[i+gap],arr[i] = arr[i],arr[i+gap]
|
||||||
|
|
||||||
|
#add 4 to array counter
|
||||||
|
arrayCounter.inputs[0].default_value += 4
|
||||||
|
arrayCounter.inputs[0].keyframe_insert(data_path='default_value', frame=iframe)
|
||||||
|
|
||||||
i=i-gap # To check left side also
|
i=i-gap # To check left side also
|
||||||
# If the element present is greater than current element
|
# If the element present is greater than current element
|
||||||
j+=1
|
j+=1
|
||||||
|
|||||||
Reference in New Issue
Block a user