January 19, 2021, 04:52:27 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Sorted Linked Type Lists by Miracle [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Sorted Linked Type Lists by Miracle [ 1+ years ago ] (Read 477 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Sorted Linked Type Lists by Miracle [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:41 AM »
Title :
Sorted Linked Type Lists
Author :
Miracle
Posted :
1+ years ago
Description :
This sort algorithm is essentially a bubble sort, which can be slow especially for very long lists.
Code :
Code: BlitzBasic
Global
NUM_COWS =
8
Type
cow
Field
z
Field
pr.cow
Field
nx.cow
End Type
Type
list
Field
firstcow.cow
Field
lastcow.cow
End Type
Global
list.list =
New
list
For
t =
1
To
NUM_COWS
moo.cow =
New
cow
mooz =
Rand
(
0
,
100
)
SortCowsOnZ
(
moo
)
Next
Print
"Unsorted list:"
For
moo.cow =
Each
cow
Print
mooz
Next
Print
Print
"Sorted list:"
moo = listfirstcow
Repeat
Print
mooz
moo = moo
x
Until
moo =
Null
WaitKey
(
)
End
Function
SortCowsOnZ
(
cow.cow
)
moo.cow = listlastcow
done =
0
If
cow
x <>
Null
And
cowpr <>
Null
Then
If
cowpr <>
Null
Then
cowpr
x = cow
x
If
cow
x <>
Null
Then
cow
xpr = cowpr
EndIf
If
moo <>
Null
Then
Repeat
If
mooz >= cowz
Then
cowpr = moo
cow
x = moo
x
If
moo
x <>
Null
Then
moo
xpr = cow
moo
x = cow
done =
1
EndIf
moo = moopr
Until
moo =
Null
Or
done =
1
EndIf
If
done =
0
Then
cow
x = listfirstcow
If
listfirstcow <>
Null
Then
listfirstcowpr = cow
EndIf
If
cow
x =
Null
Then
listlastcow = cow
If
cowpr =
Null
Then
listfirstcow = cow
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Sorted Linked Type Lists by Miracle [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal