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?

new node.prev.next = new node; new node.next.prev = ptr to_head.next; new node.next.prev = new node; new node.next.prev.prev = new node.next;

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

0 solutions

No explanations have been posted yet. Check back later!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...