A collection, BIRDWEIGHTS, exists. It stores the weights of some birds!
In IBDP Computer Science, HL students will study collections like ArrayLists.
Both HL and SL students will study collections from a conceptual point of view and will be able to write algorithms in pseudocode to process a collection.
The following simulation:
| ↑ |
Here is some pseudocode which processes each item in the collection, BIRDWEIGHTS, and outputs each weight value:
BIRDWEIGHTS.resetNext()
loop while BIRDWEIGHTS.hasNext()
item = BIRDWEIGHTS.getNext() //grab the current weight value, update the next pointer
output item
end loop
Notice how hasNext() and getNext() work together during the loop/iteration
Also, whetaver kind of data stored in the collection can easily be assigned to a variable and then processed
If we know the size of the collection we could alternatively use:
BIRDWEIGHTS.resetNext()
loop i from 0 to 9
item = BIRDWEIGHTS.getNext()
//process item
end loop