Data update

This commit is contained in:
Ingy döt Net 2024-03-06 22:25:12 -08:00
parent ed705008a8
commit 0df55f9f24
2196 changed files with 32999 additions and 3075 deletions

View file

@ -0,0 +1,29 @@
extends Node2D
func BubbleSort(_array : Array) -> void:
for i in range(_array.size() - 1):
var swapped : bool = false
for j in range(_array.size() - i - 1):
if _array[j] > _array[j + 1]:
var tmp = _array[j]
_array[j] = _array[j + 1]
_array[j + 1] = tmp
swapped = true
if not swapped:
break
return
func _ready() -> void:
var array : Array = range(-10, 10)
array.shuffle()
print("Initial array:")
print(array)
BubbleSort(array)
print("Sorted array:")
print(array)
return

View file

@ -0,0 +1,24 @@
class Comparable:
var Value
func _init(_val):
self.Value = _val
func compare(_other : Comparable) -> int:
# Here is the simple implementation of compare
# for primitive type wrapper.
return self.Value - _other.Value
func BubbleSortObjects(_array : Array) -> void:
for i in range(_array.size() - 1):
var swapped : bool = false
for j in range(_array.size() - i - 1):
if _array[j].compare(_array[j + 1]) > 0:
var tmp = _array[j]
_array[j] = _array[j + 1]
_array[j + 1] = tmp
swapped = true
if not swapped:
break
return