COMP 2012H Honors Object-Oriented Programming and Data Structures

Lab 5 Inheritance

Common Errors

  1. ArrayDeque derives from ArrayAbstractQueue. Instead can derive from ArrayQueue to reuse the functions.

  2. Not implementing Copy-Constructor and Copy-Assignment Operator, because technically unused in the lab5_main.cpp

  3. Most other errors relate to the circular array implementation.

    • In ArrayAbstractQueue:

      Copy-Constructor and Copy-Assignment Operator:
      data[i] = arrayAbstractQueue.data[(arrayAbstractQueue.headIndex + i) % arrayAbstractQueue.getArraySize()];
      But in the MIL, also copied headIndex. Either reset headIndex to 0, or use data[(headIndex + i) % getArraySize()] while copying the elements. Otherwise the copied container has a corrupted circular array.

    • In ArrayStack:

      Circular Array is completely unnecessary, if we do all operations at the tail of the array instead of the head. Then we don't need any shifting of the array at all.

    • In ArrayQueue and ArrayDeque:

      "headIndex - 1 + getArraySize()" might cause an underflow. + and - are left-to-right associativity, so we will do "headIndex - 1" first, which might go negative, and unsigned int will cause it to underflow into the largest possible unsigned int value. Then, subsequent "+ getArraySize()" might overflow back to the correct number. Still, safer to use use "headIndex + getArraySize() - 1" instead to avoid underflow/overflow.