File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,11 @@ func next(action):
54
54
return emit_signal ("mistake" )
55
55
_index += 1
56
56
if _index == array .size :
57
+ # Skip over duplicates to avoid infinite cycling
58
+ while _smaller != _pointer and array .at (_pointer ) == array .at (_smaller ):
59
+ _smaller += 1
57
60
array .swap (_pointer , _smaller )
58
- while array .at (_pointer ) == _pointer + 1 :
61
+ while array .is_in_place (_pointer ):
59
62
_pointer += 1
60
63
if _pointer == array .size :
61
64
return emit_signal ("done" )
Original file line number Diff line number Diff line change @@ -87,6 +87,17 @@ func sort(i, j):
87
87
_array = front + sorted + back
88
88
emit_signal ("sorted" , i , j )
89
89
90
+ func is_in_place (i ):
91
+ """Check if the element at index i is in its correct place."""
92
+ var less = 0
93
+ var equal = 0
94
+ for element in _array :
95
+ if element < _array [i ]:
96
+ less += 1
97
+ elif element == _array [i ]:
98
+ equal += 1
99
+ return less <= i and i < less + equal
100
+
90
101
func get_size ():
91
102
return _array .size ()
92
103
You can’t perform that action at this time.
0 commit comments