From c1a50bd84e00604db14943ad11ee523176f9c58d Mon Sep 17 00:00:00 2001 From: ForeignGods Date: Tue, 31 May 2022 17:50:58 +0200 Subject: [PATCH] Update ShellSort.py --- ShellSort.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ShellSort.py b/ShellSort.py index 622a93a..a08c581 100644 --- a/ShellSort.py +++ b/ShellSort.py @@ -92,18 +92,37 @@ for ob in bpy.data.objects: #sort array based on location.x cubes.sort(key = lambda obj: obj.location.x) -#Shell Sprt Algorithm +iframe=0 + +#Shell Sort Algorithm def shellSort(arr, n): + global iframe + gap=n//2 while gap>0: + j=gap + # Check the array in from left to right # Till the last possible index of j while j=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 # We don't do swap else we swap if arr[i+gap].scale.z > arr[i].scale.z: @@ -112,7 +131,16 @@ def shellSort(arr, n): else: arr[i+gap].location.x = i 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] + + #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 # If the element present is greater than current element