Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 3
Medium

Develop an algorithm using either pseudo-code or a flowchart that will move every block from Column 1 to Column 2.

Your algorithm should work however many blocks start in Column 1. You may assume there will always be at least one block in Column 1 at the start and that the other columns (Column 0 and Column 2) are empty at the start.

The original vertical order of the blocks must be preserved.

The MOVE(from, to) subroutine must be used to move a single block from one column index to another. You should also use the HEIGHT(column) subroutine, which returns the current number of blocks in that column.

A diagram showing three positions: Column 0, Column 1, and Column 2. Column 1 contains a stack of three blocks with block A on top of block B, which is on top of block C. Column 0 and Column 2 are empty.

After your algorithm runs, all blocks should be in Column 2 in the same initial vertical order (with block A on top of block B, on top of block C), and Columns 0 and 1 should be empty.

[4]

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms