Generic doubly linked list, Data Structure & Algorithms

Your objective is to write a generic doubly linked list class called CS228LinkedList that implements the List interface and uses a type variable T. All methods except for subList and toArray(Object[] a) must be implemented. You may throw the exception UnsupportedOperationException for subList and toArray(Object[] a). Again, you may not extend any other class when implementing the List interface.

The CS228LinkedList class contains a non-static inner class called Node. Obviously, the instances of Node serve as nodes in the linked list. The Node inner class contains six member variables: data of type T, next of type Node, prev of type Node, id of type int, nc of type int, and pc of type int. You should not declare any other member variables for the Node inner class.

As we learned, the next eld of a node refers to the next node in the list. If the next node does not exist, then next is null. The prev eld refers to the previous node in the list. If the previous node does not exist, then prev is null. The nc (next changes) eld represents the number of times the \next" node has been changed due to deletion or addition. Likewise, the pc (previous changes) eld represents the number of times the \previous" node has been changed due to deletion or addition. Finally, the id eld should hold a non-negative integer that uniquely identi es that particular node.

Along with normal nodes, the CS228LinkedList class needs to include two dummy nodes called head and tail. We consider the list to be empty if it contains only the head and tail nodes. Logically, if the list is empty, then the node next to head is tail, and the node previous to tail is head. Otherwise, the head is previous to the rst normal node, and the rst normal node is next to the head. Likewise, tail is next to the last normal node, and the last normal node is previous to the tail.

The head and tail dummy nodes must have null data elds. Also, the prev eld of head and the next eld of tail must be null. The pc eld of head and the nc eld of tail must be set to 0. When a normal node is rst created and added to the list, its pc and nc elds are set to 0.

Whenever the next eld of a node is modi ed, its nc eld is incremented by 1. Whenever the prev eld of a node is modi ed, its pc eld is incremented by 1. The inner class Node needs to include a toString() method that returns a String representation of the node. The format of a node's string representation is a sequence of values in the following order: the node's id value, the id value of the previous node, the id value of the next node, the toString() form of its data eld, the pc value of the node, and the sc value of the node. For the head, report -1 as the id value of its previous node. For tail, report -1 as the id value of its next node. The toString() form of any null data eld is the string \null". You must also write the private inner class called CS228LinkedListIterator that implements the ListIterator interface. All attributes for this class must be private. You need to implement all methods in the ListIterator interface without throwing any UnsupportedOperationException. Keep in mind that you do not have to include any checks for concurrent modi cation while implementing the CS228LinkedListIterator inner class.

Write a toString() method in the CS228LinkedList class that produces, in iterator order, the toString() representation of each node in the list. The two dummy nodes should also be reported in this list. Finally, you are allowed to use arrays only in the toArray() method.

Posted Date: 3/2/2013 2:03:38 AM | Location : United States

Related Discussions:- Generic doubly linked list, Assignment Help, Ask Question on Generic doubly linked list, Get Answer, Expert's Help, Generic doubly linked list Discussions

Write discussion on Generic doubly linked list
Your posts are moderated
Related Questions

#question. merging 4 sorted files containing 50,10,25,15 records will take time?

Technique for direct search is    Hashing is the used for direct search.

A  BST is traversed in the following order recursively: Right, root, left e output sequence will be in In Descending order

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

Regis lives in Brazil and frequently travels to USA, Japan and Europe. He wants to be able to convert Brazilian Reais into US dollars, European euros and Japanese yen. Conversion f

Advantages of First in First out (FIFO) Costing Advantages claimed for first in first  out (FIFO)  costing method are: 1. Materials used are drawn from the cost record in

draw a flowchart which prints all the even numbers between 1-50

Q. Define a sparse matrix. Explain different types of sparse matrices? Show how a triangular array is stored in memory. Evaluate the method to calculate address of any element ajk

Define Spanning Tree A Spanning Tree of a connected graph is its linked acyclic sub graph (i.e., a tree) that having all the vertices of the graph.