CPSC 211, Sec 201-203: Quiz 4
Feb 11, 2004

Name:________________________________________

  1. (2 pts) Recall the generic priority queue implementation, in which the data objects can be of any type, as long as it implements an interface called ComparisonKey. The main operations of the PriorityQueue class are
    public void insert(ComparisonKey x);
    public ComparisonKey remove(); 
    
    List one advantage and one disadvantage of this approach as compared to implementing a priority queue with integer keys.











  2. (2 pts) Recall the program that sorted keys of any type using the generic priority queue:
    void sortPQ(ComparisonKey[] A) {
       int n = A.length;
       PriorityQueue pq = new PriorityQueue();
       for (int i = 0; i < n; i++) pq.insert(A[i]);
       for (int i = 0; i < n; i++) A[i] = pq.remove();
    }
    
    What steps would you have to take to use sortPQ above to sort an array of doubles?











  3. (1 pt) C does not have a built-in boolean data type. But boolean expressions (expressions that are either true or false) are required for constructs such as loops (e.g., for statements) and conditionals (e.g., if statements). What is the analog in C of a boolean expression and how are truth values represented?