×

Objectives

Students will be able to:

  • design algorithms using pseudocode
  • translate pseudocode into program code and vice versa
  • translate translate flowcharts into pseudocode and vice versa
  • perform whitebox testing on a given algorithm

Collections

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:

  • resets a next pointer to start at the beginning of a collection, ready for processing.
  • loops through the collection while it has an element to be processed:
  • gets the next element and updates the next pointer
  • processes in some way the element that it just grabbed

A Collection, BIRDWEIGHTS

↑

Current Bird Weight   ---

Observations

  • A collection does not use indexes like arrays do.
  • .resetNext() sets the next pointer to the beginning of the collection.
  • .getNext() grabs the next item in the collection and updates the next pointer
  • without using indexes, how can we iterate through the collection? ie we cannot use BIRDS.length

Sample Pseudocode

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

Worksheet

Complete the Worksheet.

Helper Video

Here is a helper video if you have no idea what is going on!