Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
53 views1 page

Assignment 2 DSA

This document discusses implementing a queue using a circular linked list. It notes that a circular linked list has no null nodes and the last node references the first node, forming a circle. This allows representing the queue with just a single reference to the last node. When needed, the first node can be accessed from the last node. The task is to write a CircularLinkedQueue class implementing the QueueInterface using this single reference approach.

Uploaded by

Abdullah Atiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Assignment 2 DSA

This document discusses implementing a queue using a circular linked list. It notes that a circular linked list has no null nodes and the last node references the first node, forming a circle. This allows representing the queue with just a single reference to the last node. When needed, the first node can be accessed from the last node. The task is to write a CircularLinkedQueue class implementing the QueueInterface using this single reference approach.

Uploaded by

Abdullah Atiq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DSA Assignment No.

Circular Linked Implementations of a Queue


This chain for our queue has two external references: one to the first node and one to the last
node in the chain. Recall that these references are particularly useful for a queue
implementation, since a queue’s operations affect both of its ends. Like the chains you have seen
before, the last node in this chain contains null. Such chains are sometimes called linear linked
chains, regardless of whether they have a tail reference in addition to a head reference.
In a circular linked chain, the last node references the first node, so no node contains null in its
next field. Despite the fact that each node references the next node, a circular linked chain has a
beginning and an end. We could have an external reference to the chain’s first node, but then a
traversal of the chain would be necessary to locate the last node. Having both a reference to the
first node and a reference to the last node is usually more than is necessary. Since the chain’s last
node references its first node, we can have a solitary reference to the last node and still locate
the first node quickly. Figure below illustrates such a chain.
When a class uses a circular linked chain to represent a queue, its only data field is the reference
lastNode to the chain’s last node. The implementation therefore does not have the overhead of
maintaining a data field that references the first node. Any time such a reference is needed, the
expression lastNode.getNextNode() provides it. Despite this simplification, this approach is not
necessarily better than the one we used. It is mostly just different.

Tasks
1. Write a class CircularLinkedQueue (using the approach discussed above) which
implements the QueueInterface (we used in our lectures).

Reference:
Carrano, Frank M, and Timothy M Henry. “Chapter 11: Queue, Deque, and Priority Queue
Implementations.” Data Structures and Abstractions with Java, 4th ed., Pearson, 2015, pp. 334–
335.

You might also like