Know your data structures!

mult-tasking

mult-tasking

Some operating systems use a process management scheme called round robin scheduling. It is implemented in the kernel to allow for running multiple processes at once. The backbone behind this method is a circular, doubly-linked list.

The job of insert is to insert the object to which new_node points at the head of the given linked list, which is given by following the pointer in ptr_to_head

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
void insert (ptr ptr_to_head, ptr new_node) {
   ptr head = *ptr_to_head;
   if (head == null) {
     new_node.next = new_node;
    new_node.prev = new_node;
   } else {
     new_node.next = head;
    new_node.prev = head.prev;
       !!!!!!!!!!!!!!MISSING!!!!!!!!!!!!!!!!!!!!!!!!!!!
    new_node.prev.next = new_node
   }
   *ptr_to_head = new_node;

The procedure above is only missing one line (line 9). Which of the following is the correct line that should be there?

×

Problem Loading...

Note Loading...

Set Loading...