Gamemaker Bubble Sort

Information about object: obj_sort
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

names=ds_list_create();//create a list
ds_list_add(names,"Nick","Steve","Chris","Nigle","Bob","Alice","Ben","Harry","Katherine","Guy","Sam");//add null (not used) and add names
size=ds_list_size(names);
repeat(size)//repeat
{
for (var i = 0; i < size; i += 1)//send an position to check
{
if names[|i]>names[|i+1]//compare two names
{
//swap pairs if true
temp=names[|i];//hold temp value
names[|i]=names[|i+1];//swap
names[|i+1]=temp;//add temp back in other poaition
}
}
}

Draw Event:
execute code:

for (var i = 1; i < 11; i += 1)//loop through
{
draw_text(50,50*i,names[|i]);//draw value
}

No comments:

When Bad People Make Good Art

I offer six guidelines on cancel culture ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏...

Contact Form

Name

Email *

Message *