Test 2 Booster, CPS 100E, Fall 1995

You MUST work alone on these problems. You may consult your book and your notes. These problems are due ON PAPER at the beginning of class on Tuesday, December 5. If you aren't in class you MUST turn the problems in before class, no papers will be accepted after class.

Problem 1: (2 points)

Two queues are equal if they store the same values in the same order.

Complete the body of operator == below so that it returns true if the queues of strings s and t are equal. Note that the queues are const parameters so that they cannot be dequeued (you'll need to make copies if you want to dequeue).

  bool operator == (const Queue<string> & s, const Queue<string> & t)
  // postcondition: returns true if s == t, i.e., contains the same values
  //                in the same order, returns false otherwise

Problem 2: (4 points)

By definition for queues s and t, s < t (s is less than t) if all the elements in s are also in t AND are in the same order. For example: (the front of the queues is the left)
        s               t                   s < t

      a b c         p a d f b g c           true
      a b c         a d f c g b             false
Write operator < that will return true if one queue of strings is less than another (the operator should have two parameters, both passed as const reference as in the case of operator == in Problem 1).