staff project download information miscellaneous
Trend Download   One Dimensional Bubble Sort
  Download

Trend Tutorials
Trend Basics
Game of Life
One Dimensional CA
Mouse Maze
1-D Bubble Sort
Animation


More Trend Examples

 
MangoVect DownloadPicky DownloadLucy2 DownloadGRAMAUBViz DownloadgeneDBN Download
2. Examining the rule (continued)

Line 15 is the alternative to the if statement started in line 8. Although line 15 is an else statement that serves as a "catch all", it basically means when the "flip" field is equal to '>', then execute the statements that follow.

15 else {

Line 16 is similar to line 9. But line 16 states that the neighbor to the east will be given focus rather than the cell to the east. Again this allows for comparison between the two cells to find the higher "value" field.

16 target: = ea:;

Line 17 below is the same as line 10. If the "value" field is not equal to 0 and the neighbor's "value" field is not equal to 0, then execute the statement that follows.

17 if (value != 0 && target:value != 0)

Line 18 has the condition that if the "value" field for the neighbor in focus is less than the "value" field for the current cell, then execute the statement that follows, which is line 19.

18 if (target:value < value)

Line 19 is executed if the condition in line 18 is found to be true.

19 value = target:value;

The statement in line 19 is an assignment of the "value" field of the current cell. Assigning it the value of the "value" field of the neighbor cell in focus to the current cell. In other words, copy the value of the eastern neighbor to the current cell.

To recap lines 15through 19. If the "flip" field is equal to '>', give the eastern neighbor focus for this epoch. Then compare the current cell's "value" field with the neighbor. If the neighbor's "value" field is less than the current cell's "value" field, copy the value of the neighbor's "value" field to the current cell.

In more laymen's terms, check the neighbor cell to see if it has a smaller value. If so, copy that value to yourself.

After the selection process of the nested if statements, is a statement that will execute regardless of whether the if statements were proven true or false. Line 20 states that the "flip" field will change its symbol from '>' to '<'. Essentially, it flips the value from greater than, to less than. This will cause the "flip" field value to be different for the next epoch.

20 flip ='<';
21 }
22 }

Lines 21 and 22 just close out the else statements started in lines 7 and 15.

The One Dimensional Bubble Sort gives the same result as a traditional bubble sort algorithm, it just goes about it in a different way. Although it is not as efficient as a quick sort, it gets the job done. For an animated demonstration of the results of the 1-D Bubble Sort, check out the 1-D Bubble Sort animation.

For information on how to link colors to particular cell values, view the the tutorial on Animation.

Last modified June 13, 2008 . All rights reserved.

Contact Webmaster

lab