UNLV CS 477/677 Spring 2015 Assignment 2
University of Nevada Las Vegas
Howard R. Hughes College of Engineering
Department of Computer Science
My Home Page
Course Page

CSC 477/677 Assignment 2

Due date: Tuesday, February 10, 2015, 2:30 PM.

All assignments must be handwritten (not typed or printed from a computer file) in your own handwriting, on 8.5 by 11 inch paper, or on A4 paper. Write your name on each sheet, and do not fold the pages or crimp the corners. (You may use a paper clip or a staple.)
Turn the pages in to me or to the graduate assistant on or before the due date.

  1. Assume that the variable S in the code below has type stack of integer and that the operators pop, push, empty, and initialize are properly implemented.
    What will the output be if the code is executed?
    initialialize(S);
    push(S,4);
    push(S,2);
    push(S,8);
    cout << pop(S) << endl;
    push(S,5);
    push(S,pop(S)+1);
    while(not empty(S))
      cout << pop(S) << endl;
    
  2. Assume that the variable H in the code below has type min-heap of integer and that the operators delete-min, insert, empty, and initialize are properly implemented.
    What will the output be if the code is executed?
    initialialize(H);
    insert(H,3);
    insert(H,1);
    insert(H,8);
    cout << delete-min(H) << endl;
    insert(H,4);
    insert(H,delete-min(H)+2);
    while(not empty(H))
      cout << delete-min(H) << endl;
    
  3. In class, I showed how to implement the abstract data type queue as a circular linked list with a single pointer. Assume that the variable Q in the code below has type queue of integer, implemented as a circular linked list, and all the operators are properly implemented, as shown in class.
    Show, by drawing figures, the appearance of the linked list after each statement in the code below is executed. You should draw five figures.
    intialize(Q);
    enqueue(Q,5);
    enqueue(Q,3);
    cout << dequeue(Q) << endl;
    enqueue(Q,2);
    

Back to Course Page