Tracing a faulty range move

A job editor initially stores nodes A through H in that order in a doubly linked list. head points to A, tail points to H, A.prev = null, and H.next = null. There are no extra boundary nodes.


A programmer intends to move the consecutive range B, C, D immediately after G. The variables first, last, and destination hold references to B, D, and G, respectively. These variables continue to refer to those same nodes throughout the code.


The following faulty Python-style code changes node fields. Execute assignments in the written order; do not substitute the intended result.


Eight nodes A through H form the initial doubly linked list, with first at B, last at D, and destination at G.


Python
before = first.prev
after = last.next
before.next = after
after.prev = before
destination.next = first
first.prev = destination
last.next = destination.next
destination.next.prev = last


After all assignments, identify the node referenced by last.next and the node referenced by first.prev. Also count the distinct nodes reached by starting at head and repeatedly following next, including the starting node and stopping before visiting a node twice or upon reaching null. Give node names as single letters and the count in nodes as an integer to zero decimal places.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Doubly Linked Lists Questions: