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
Q. Describe the adjacency matrix and make the same for the given undirected graph.    Ans: The representation of Adjacency Matrix: This representation consists of

what is tower of management with example

3. A function to convert a complex number in algebraic form to a complex number in phasor form

Importance of Object-Oriented over java Java is basically based on OOP notions of classes and objects. Java uses a formal OOP type system that should be obeyed at compile-t

Big oh notation (O) : The upper bound for the function 'f' is given by the big oh notation (O). Considering 'g' to be a function from the non-negative integers to the positive real

The time needed to delete a node x from a doubly linked list having n nodes is O (1)

What are stored and derived attributes?  Stored attributes: The attributes kept in a data base are called stored attributes.  Derived attributes: The attributes that are

An adjacency matrix representation of a graph cannot having information of : Parallel edges

Q. Explain the insertion sort with a proper algorithm. What is the complication of insertion sort in the worst case?

need an expert to help me with the assignment