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

Continuing the examination of the rule for the One Dimensional Bubble Sort brings line 6. Line 6 is the closing curly brace that simply closes the block of statements in line 5.

6 }

Line 7 is the else related to the if started in line 4. Along with a right curly brace to include more than one statement after the "catch all" condition.

7 else {

Line 8 is a nested if that checks the value of the "flip" field. Line 8 states that if the "flip" field is equal to the symbol '<', then execute that statement that follows in line 9.

8 if (flip = = '<') {
9 target: = we:;

Line 9 says to make the western neighbor cell, the neighbor cell in focus. This allows the code to compare two cells that are side by side for that particular epoch. The comparison starts in line 10 and continues in line 11.

10 if (value !=0 && target:value !=0)
11 if (target:value > value)

Line 10 is another nested if with the condition that states if the field "value" is not equal to 0 and the "value" field for the neighbor cell in focus is not equal to 0, then execute the statement that follows. The statement that follows is another if statement. Line 11 has the condition that if the "value" field for the neighbor in focus is greater than the "value" field for the current cell, then execute the statement that follows, which is line 12.

12 value = target:value;

The statement in line 12 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.

To recap lines 7 through 12. If the "flip" field is equal to '<', give the western neighbor focus for this epoch. Then compare the current cell's "value" field with the neighbor. If the neighbor's "value" field is greater 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 larger 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 13 states that the "flip" field will change its symbol from '<' to '>'. Essentially, it flips the value from less than, to a greater than. This will cause the "flip" field value to be different for the next epoch.

13 flip = '>';

Line 14 is the right curly brace to close the nested if started in line 8.

14 }

To show the rule in action, the pictures below show only the "flip" field in the first two epochs. Notice that the symbols switch, or flip from '<' to '>' and vice versa.

The images are only a small snapshot of the CA screen, but looking at the first cell in the upper left-hand corner for epoch 0, the symbol is '>'. Then in the epoch 1, the symbol has changed to '<'. Each of the "flip" fields changes after each epoch. This allows each cell to compare itself with the neighbor to the east during one epoch, and then to the west for the next epoch.


Last modified June 13, 2008 . All rights reserved.

Contact Webmaster

lab