Created 07/09/03; edited 06/20/2015


Quiz on Linked Lists

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.


1. Here is a description of one node of a linked list (using the language C):

struct size
{
  int width;
  int height;
  struct size *next;  // this means a pointer to
                      // the next node.
} ;

This describes a node that consists of two integers followed by an address.

Which of the following code fragments dynamically allocates enough memory for the node and puts its address in $s0 ?

A.   
li      $v0,9
li      $a0,12
syscall
move    $s1,$v0
B.   
li      $v0,12
li      $a0,8
syscall
move    $s1,$v0
C.   
li      $v0,12
li      $a0,8
syscall
move    $v0,$s1
D.   
li      $v0,12
li      $a0,8
syscall
move    $a0,$s1

2. Here (again) is a description of one node of a linked list:

struct size
{
  int width;
  int height;
  struct size *next;  // this means a pointer to
                      // the next node.
} ;

Assume that the address of a node is in $v0. Which of the following puts a width of 12 and a height of 17 into the node?

A.   
li    $t0,17
sw    $t0,0($v0)
li    $t0,12
sw    $t0,4($v0)
B.   
li    $t0,12
sw    $t0,4($v0)
li    $t0,17
sw    $t0,0($v0)
C.   
li    $t0,12
sw    $t0,0($v0)
li    $t0,17
sw    $t0,4($v0)
D.   
li    $t0,12
sw    $v0,0($t0)
li    $t0,17
sw    $v0,4($t0)

3. Here is a description of one node of a linked list:

struct size
{
  int width;
  int height;
  struct size *next;  // this means a pointer to
                      // the next node.
} ;

Assume that $s1 points at node 1 and that $s2 points at node 2. Which of the following makes node 2 the successor of node 1?

A.    sw $s2,4($s1)
B.    sw $s2,8($s1)
C.    sw $s1,0($s2)
D.    sw $s1,4($s2)

4. Here is a description of one node of a linked list:

struct size
{
  int width;
  int height;
  struct size *next;  // this means a pointer to
                      // the next node.
} ;

The field head contains the address of a linked list of such nodes. Which of the following segments visits each node of the list?

A.   
        lw     $s0,done
loop:   beqz   $s0,head
        . . .              # do something
        lw     $s0,4($s0)
        b      loop
        
done:
B.   
        lw     $s0,head
loop:   beqz   $s0,done
        . . .              # do something
        lw     $s0,$s0
        b      loop        
done:
C.   
        lw     $s0,head
loop:   beqz   $s0,done
        . . .              # do something
        lw     $s0,8($s0)
        b      loop        
done:
D.   
        lw     $s0,head
loop:   beqz   $s0,done
        . . .              # do something
        sw     $s0,4($s0)
        b      loop        
done:

5. Here is a description of one node of a linked list:

struct size
{
  int width;
  int height;
  struct size *next;  // this means a pointer to
                      // the next node.
} ;

Assume that $s0 is pointing to the last node of a linked list. Which of the following code segments attaches one more node to the list and points $s0 to it?

A.   
       li      $v0,9
       li      $a0,12
       syscall
       sw      $v0,8($s0)
       move    $s0,$v0
B.   
       li      $v0,9
       li      $a0,12
       syscall
       sw      $v0,8($v0)
       move    $s0,$v0
C.   
       li      $v0,9
       li      $a0,8
       syscall
       sw      $v0,4($v0)
       move    $s0,$v0
D.   
       li      $v0,12
       li      $a0,8
       syscall
       sw      $v0,8($v0)
       move    $s0,$v0


   The number you got right:       Percent Correct:       Letter Grade:   


Click here

If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.