CS 1723-001 Data Structures
Fall 2001 -- Mid-Term Exam
Directions: Use your own paper for answers. When you are done you may keep this exam sheet and should pick up an answer sheet.

  1. Here are two separate questions related to RPN (Reverse Polish Notation):

    1. Consider the following arithmetic expression:
      
            3^2*(4-2)+6
         
      1. In translating this arithmetic expression to RPN, what kinds of items are pushed on a stack?
      2. Give the RPN that corresponds to this expression. (Just give the answer. You don't need to show where it comes from. Your answer should have the operands (the numbers) in the same order as the original.)

    2. Consider the following arithmetic expression in RPN form (not the same as the answer to part (a) above):
      
            34*23^8+/
         
      Use the technique that was presented in class to evaluate the resulting RPN, showing step-by-step the use of a stack.

  2. Consider the Java library Stack class, with methods pop, push, and empty, and with exception EmptyStackException. Fill in code in the framework below to do what the boldface items call for. (Write on a separate sheet of paper, without recopying the code or comments that are given.)
  3. Consider the following hierarchy of classes:
    1. Write a class Staff that extends Employee above. The new class should have an extra private int data field percentTime that gives the percent time the staff member works (100 = full-time, 50 = half-time, etc.).

    2. Show additions to the Persons class to add another person to the array: a new staff member with name Wheeler, Jason, ssn 458-67-2100, age 34, salary 17000, and percent time 75.

    3. Suppose we want to add objects of type Person to a list of Comparable items, as we did in class. Suppose we then want to remove the objects in decreasing order of age, using the removeMin method in the general CompList class we had before. Indicate clearly what changes and additions are needed to the class hierarchy above? (Then the list becomes a priority queue, where the priority is the age of the person, so that older people get preference over younger ones.) Are any changes needed to the code for the list itself.

    4. Assuming that the five people in the code above, along with the extra person in part (b) above have all been added to an instance of the CompList class, give code that will remove all these people in decreasing order of age, printing information about them as they are removed. [Note: the CompList class works with a list of Comparable objects. The class has methods add, remove, isEmpty, and removeMin.]

    Points for each problem: 1-20, 2-30, 3-50.