• edited by
48,554 views
82 82 votes

A circularly linked list is used to represent a Queue. A single variable $p$ is used to access the Queue. To which node should $p$ point such that both the operations $\text{enQueue}$ and $\text{deQueue}$ can be performed in constant time?

  1. rear node
  2. front node
  3. not possible with a single pointer
  4. node next to front

13 Answers

–2 –2 votes
I think there is no front or rear pointer here only p pointer so enQueue() and deQueue operation should be this

1.) newNode-->next=p-->next-->next;

2.) p-->next-->next=NULL;

3.) free(p-->next);

4.) p-->next=newNode;
Answer:
Position:
Show:

Related questions

96 96 votes
6 answers 6 answers
30.1k
30.1k views
Kathleen asked Sep 18, 2014
30,118 views
Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among $\text{union, intersection, membership, cardinality}$ wil...
160 160 votes
16 answers 16 answers
60.8k
60.8k views
Kathleen asked Sep 18, 2014
60,824 views
A program takes as input a balanced binary search tree with $n$ leaf nodes and computes the value of a function $g(x)$ for each node $x$. If the cost of computing $g(x)$ ...
56 56 votes
3 answers 3 answers
14.2k
14.2k views
Kathleen asked Sep 18, 2014
14,188 views
Consider the following C program segmentstruct CellNode{ struct CellNode *leftChild int element; struct CellNode *rightChild; }; int Dosomething (struct CellNode *ptr) { ...
42 42 votes
3 answers 3 answers
14.1k
14.1k views
Kathleen asked Sep 18, 2014
14,071 views
Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely?preorder and postorderi...