Examples in Gambas (#5) by @vdelacruzjardon
This commit is contained in:
committed by
Aditya Bhargava
parent
e2a4153e80
commit
0aec97dbf2
BIN
02_selection_sort/gambas/01_selection_sort/.gambas/MMAIN
Normal file
BIN
02_selection_sort/gambas/01_selection_sort/.gambas/MMAIN
Normal file
Binary file not shown.
4
02_selection_sort/gambas/01_selection_sort/.project
Normal file
4
02_selection_sort/gambas/01_selection_sort/.project
Normal file
@@ -0,0 +1,4 @@
|
||||
# Gambas Project File 3.0
|
||||
Title=01_selection_sort
|
||||
Startup=MMain
|
||||
|
||||
40
02_selection_sort/gambas/01_selection_sort/.src/MMain.module
Normal file
40
02_selection_sort/gambas/01_selection_sort/.src/MMain.module
Normal file
@@ -0,0 +1,40 @@
|
||||
' Gambas module file
|
||||
|
||||
Function findSmallest(arr As Float[]) As Integer
|
||||
Dim smallest As Float
|
||||
Dim i, smallest_index As Integer
|
||||
smallest_index = 0
|
||||
smallest = arr[0]
|
||||
For i = 1 To arr.Length - 1
|
||||
If arr[i] < smallest Then
|
||||
smallest = arr[i]
|
||||
smallest_index = i
|
||||
Endif
|
||||
Next
|
||||
Return smallest_index
|
||||
|
||||
End
|
||||
Function selectionSort(arr As Float[]) As Float[]
|
||||
Dim newArr As New Float[]
|
||||
Dim smallest, i As Integer
|
||||
Dim element As Float
|
||||
For i = 0 To arr.Length - 1
|
||||
smallest = findSmallest(arr)
|
||||
newArr.Push(arr[smallest])
|
||||
arr.Remove(smallest)
|
||||
Next
|
||||
|
||||
Return newArr
|
||||
|
||||
End
|
||||
Public Sub Main()
|
||||
Dim r As New Float[]
|
||||
Dim element As Float
|
||||
Dim i As Integer
|
||||
r = [5, 3, 6, 2, 10]
|
||||
r = selectionSort(r)
|
||||
|
||||
For Each element In r
|
||||
Print element
|
||||
Next
|
||||
End
|
||||
7
02_selection_sort/gambas/01_selection_sort/.startup
Normal file
7
02_selection_sort/gambas/01_selection_sort/.startup
Normal file
@@ -0,0 +1,7 @@
|
||||
MMain
|
||||
01_selection_sort
|
||||
0
|
||||
0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user