183 views
6 6 votes

The UNIX editor $\texttt{vi}$ allows searching in both directions, and if the search reaches one end, it wraps around and continues from the other end.

If the sequence of lines is stored as a linked list, which representation is most reasonable?

  1. Singly linked list
     
  2. Doubly linked list
     
  3. Circular singly linked list
     
  4. Circular doubly linked list
     
  5. None of the above

2 Answers

1 1 vote

Searching in both directions needs forward and backward movement, so a doubly linked list is needed.

Wraparound means after the last node we should be able to move to the first node, and before the first node we should be able to move to the last node. 

That needs circular links.

So the best choice is a circular doubly linked list.

1 1 vote

To go forwards and backwards easily we would need a doubly linked list.
To wraparound easily we would need circular linked list.
While it would be almost as easy to wraparound with a doubly linked list with front and rear pointers, 
it would be simplest and most straightforward with a Circular Doubly Linked List

Answer: D

Answer:
Position:
Show:

Related questions

6 6 votes
3 3 answers
182
182 views
GO Classes asked Jul 6
182 views
A circular linked list has $n$ nodes. A function prints every node exactly once and stops when it reaches the starting node again.What is the running time of printing the...
6 6 votes
2 2 answers
206
206 views
GO Classes asked Jul 6
206 views
A singly linked list contains $n$ nodes. We want to reverse the order of the elements in the linked list by changing links, not by copying all elements into an array.Whic...
8 8 votes
2 2 answers
202
202 views
GO Classes asked Jul 6
202 views
Consider the following C-style code fragment for reversing a non-empty singly linked list:curr = front; next = curr->next; prev = NULL; while (curr != NULL) { (*) } front...
7 7 votes
2 2 answers
200
200 views
GO Classes asked Jul 6
200 views
The following function is supposed to reverse a singly linked list:struct node { int data; struct node *next; }; static void reverse(struct node head_ref) { struct node ...