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

Determine the term - loops, Loops There are 3 common ways of performin...

Loops There are 3 common ways of performing a looping function: for ... to ... next, while ... endwhile and repeat ... until The below example input 100 numbers and find

Write functions for both addition and subtraction, You will write functions...

You will write functions for both addition and subtraction of two numbers encoded in your data structure. These functions should not be hard to write. Remember how you add and subt

Interest, I =PR/12 Numbers of years .Interest rate up to 1yrs ...

I =PR/12 Numbers of years .Interest rate up to 1yrs . 5.50 up to 5yrs . 6.50 More than 5 yrs . 6.75 design an algorithm based on the above information

File organization, Define File organization''s and it''s types

Define File organization''s and it''s types

Depth-First Traversal, With the help of a program and a numerical example e...

With the help of a program and a numerical example explain the Depth First Traversal of a tree.

#title., Ask quapplication of data structure estion #Minimum 100 words acce...

Ask quapplication of data structure estion #Minimum 100 words accepted#

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))

Define wire-frame model, Define Wire-frame Model This skeletal view is ...

Define Wire-frame Model This skeletal view is called a Wire-frame Model. Although not a realistic representation  of the object, it is still very useful in the early stages of

Complexity, Complexity : How do the resource needs of a program or algorith...

Complexity : How do the resource needs of a program or algorithm scale (the growth of resource requirements as a function of input). In other words, what happens with the performan

Explain the memory function method, Explain the Memory Function method ...

Explain the Memory Function method The Memory Function method seeks to combine strengths of the top  down and bottom-up approaches  to  solving  problems  with  overlapping  su

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