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:

What is Security Engineering? Part 2.

A broad overview of the ever-developing security engineering field; a domain that can feel intimidating to some software engineers. With Nie...

Contact Form

Name

Email *

Message *