Generic doubly linked list, Data Structure & Algorithms

Assignment Help:

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.


Related Discussions:- Generic doubly linked list

Breadth first search, While BFS is applied, the vertices of the graph are d...

While BFS is applied, the vertices of the graph are divided into two categories. The vertices, that are visited as part of the search & those vertices that are not visited as part

Graph, multilist representation of graph

multilist representation of graph

What is a data structure, Question 1 What is a data structure? Discuss bri...

Question 1 What is a data structure? Discuss briefly on types of data structures Question 2 Explain the insertion and deletion operation of linked list in detail Question

Preorder traversal of a binary tree, Preorder traversal of a binary tree ...

Preorder traversal of a binary tree struct NODE { struct NODE *left; int value;     /* can take any data type */ struct NODE *right; };   preorder(struct N

Space-complexity of the algorithm, The space-complexity of the algorithm is...

The space-complexity of the algorithm is a constant. It just needs space of three integers m, n and t. Thus, the space complexity is O(1). The time complexity based on the loop

Procedure of analysis of algorithm, Example 1:  Following are Simple sequen...

Example 1:  Following are Simple sequence of statements Statement 1;  Statement 2; ... ... Statement k; The entire time can be found out through adding the times for

Big o notation, This notation gives an upper bound for a function to within...

This notation gives an upper bound for a function to within a constant factor. Given Figure illustrates the plot of f(n) = O(g(n)) depend on big O notation. We write f(n) = O(g(n))

Explain the method of overlapping and intersecting, Overlapping or Interse...

Overlapping or Intersecting A polygon overlaps or intersects the current background if any of its sides cuts the edges of the viewport as depicted at the top right corner of th

The quick sort algorithm exploit design technique, The quick sort algorithm...

The quick sort algorithm exploit design technique Divide and Conquer

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd