CS210 Lab: Queue Prelab Answers


Prelab Answers:

The following are the prelab questions and answers.

  1. Give the values of the following expressions
  2. a.  ptr1->data    22
    b.  ptr2->next->data    75
    c.  head->next->next->data    34
  3. Are the following expressions true or false
  4. a.  head->next == ptr1    TRUE
    b.  ptr1->next->data== 46    FALSE
    c.  ptr2->next == NULL    FALSE
    d.  head->data == 12    TRUE
  5. Decide whether the syntax of each of the following statements is valid or invalid. If it is valid, mark it as such; if it is invalid, explain what is wrong.
    a.  head->next = ptr1->next;    VALID
    b.  head->next = *(ptr2->next);    INVALID--cannot assign a "LinkNode" to a "NodePointer". The following is correct: head->next = ptr2->next;
    c.  *head = ptr2;    INVALID--cannot assign a "NodePointer" to a "LinkNode". The following is correct: head = ptr2;
    d.  ptr2 = ptr1->next->data;    INVALID--cannot asssign an "integer" to a "NodePointer". The following is correct: ptr2->data = ptr1->next->data;
    e.  ptr1->data = ptr2->data;    VALID
    f.  ptr2 = ptr2->next->next;    VALID
  6. Write one statement to do each of the following:
    a.  Make head point to the node containing 34.    head = ptr1->next;
    b.  Make ptr2 point to the last node in the list.    ptr2 = ptr2->next;
    c.  Make head point to an empty list.    head = NULL;
    d.  Set the data member of the node containing 34 to 45.    ptr1->next->data = 45;

Back to Exercise click here
Back to Queue Lab click here

CS Dept Home Page
CS Dept Class Files
CS210 Class Files

Copyright: Department of Computer Science, University of Regina.