CP1300 Stacks and Queues

(Chapter 15)
Last modified Tuesday, 05-Sep-2000 00:57:35 UTC.

Content


Self assessments


Tutorial Questions


Exam style questions

  1. Name and briefly describe the basic operations that are performed on stacks.
  2. Convert the following infix expressions to postfix
  3. Show the sequence of stack contents for the evaluation of the following postfix expression, using the values A=3, B=5, C=6, D=-4.
  4. Three basic operations that are performed on stacks are: Write the header file for a C++ class of stacks, for up to 100 integers, with these operations and a default constructor. The stack data must be stored in an array. The push and pop operations must return a Boolean value indicating their success (you may use the boolean type defined in boolean.h).
  5. Three basic operations that are performed on queues are: Following is a header file for a C++ class of queues, for up to 100 integers, with these operations and a default constructor. Write the implementation for the Initialise and Enqueue member functions, using the "wrap-around" implementation of queues with an array.
    #include "boolean.h"
    
    const int MAX_QUEUE = 100;
    typedef int queue_type[MAX_QUEUE];
    //--------------------------------------------------------------
    class queue {
    
    public:
    
    queue(void);
    void Initialize(void);
    boolean Enqueue(int Item);
    boolean Dequeue(int& Item);
    
    private:
    
    queue_type TheQueue;
    int Front,Rear;
    };