Write a generic linked list class named AdaptiveList

Assignment Help JAVA Programming
Reference no: EM131688978

Assignment: An Adaptive List - Topic: Computer Science (data structure java)

Introduction

This assignment gives you an opportunity to work with a linked data structure by implementing the java.util.List and java.util.ListIterator interfaces through an adaptive list. This adaptive list is a doubly linked list complemented by an array for indexed read operations (like get(int pos))andindexedwriteoperations(like set(int pos, E obj)). The adaptive list is much more e!cient than the doubly linked list for supporting a long sequence of indexed read/write operations ?anked by add() and remove() operations.

Requirements of the AdaptiveList class

Write a generic linked list class named AdaptiveList. Your class must implement the java.util.List interface. You may find it helpful to read the Javadoc for the interface along with its iteratorsubinterface. All the methods except subList method in the interface as well as a few additional methods must be implemented with-out throwing an UnsupportedOperationException. You may throw an UnsupportedOperationException for the subList method. Note that for some of the methods, we provide their implementations as examples for you to study or for showing the list/array created by your code; you just need to implement the other methods with the comment line // TODO. You are not allowed to use any Collection class in your implementation.

The AdaptiveList class has a non-static inner class named ListNode whose in- stances serve as nodes in the doubly linked list. The inner class has three member variables: data of generic type E, link of type ListNode, prev of type ListNode, No additional member variables in the ListNode class are allowed. The link field of a node refers to its successor node in the list if the successor node exists and is null otherwise. The prev field of a node refers to its predecessor node in the list if the predecessor node exits and is null otherwise. Every AdaptiveList list must have two dummy nodes named head and tail along with normal nodes. The list is empty if it has no normal nodes. If the list is empty, then head is the predecessor of tail and tail is the successor of head. Otherwise, head is the predecessor of the first normal node and the first normal node is the successor node of head; tail is the successor of the last normal node and the last normal node is the predecessor of tail. The data fields of head and tail are always null. The prev field of head and the link field of tail are always null.

Write a private inner class named AdaptiveListIterator to implement the ListIterator interface. You should implement all methods in the ListIterator interface without throwing any UnsupportedOperationException. There is no need to keep a coherent list if there is concurrent modi?cation to the list. In other words, the iterator does not have to be a failfast iterator.

In addition to the doubly linked list, the AdaptiveList class keeps an array of type E elements for implementing the get(int pos), set(int pos, E obj) and reverse() methods efficiently. Note that the reverse() method swaps the elements at indexes 0 and n ! 1, at indexes 1 and n ! 2, and so on, so that the order of the elements in the array of length n is reversed. The method returns false if n ≤ 1 and true otherwise. This method needs to be implemented without using any additional array.

The doubly linked list and the array are alternately used as follows. The class keeps two boolean ?elds named linkedUTD and arrayUTD (UTD stands for Up To Date): linkedUTD is true if the doubly linked list is used to represent the current sequence of data items and false otherwise; arrayUTD is true if the array is used to represent the current sequence of data items and false otherwise. At any time, the current sequence of data items is represented either by the doubly linked list or by the array; so at least one of linkedUTD and arrayUTD is true. The doubly linked list is used to implement all methods except for the get(int pos), set(int pos, Eobj) and reverse() methods, which are implemented by using the array. These implementations are facilitated by using two helper methods: The updateLinked() method creates a new doubly linked list with numItems normal nodes by copying the current sequence of data items from the array to the doubly linked list and setting linkedUTD to true, whereas the updateArray() method creates a new array of length numItems by copying the current sequence of data items from the doubly linked list to the array and setting arrayUTD to true. If a method is to be implemented by using the doubly linked list but linkedUTD is false, then updateLinked() needs to be called before the implementation and at the end arrayUTD needs to be set to false if the doubly linked list is modi?ed by the method so that the array is no longer up to date. Similarly, if a method is to be implemented by using the array but arrayUTD is false, then updateArray() needs to be called before the implementation and at the end linkedUTD needs to be set to false if the array is modi?ed by the Set() or reverse() method (see the following example).

Attachment:- Assignment Files.rar

Reference no: EM131688978

Questions Cloud

Demonstrate college-level communication through composition : Demonstrate college-level communication through the composition of original materials in Standard English.
Compute probability that committee will contain none of them : The dean of a business school wishes to form an executive committee of 5 from among the 40 tenured faculty members at the school.
Compare and contrast that strategy to innovative strategy : Identify their big idea that started the company's innovation and describe their strategy at that time. Compare and contrast that strategy to their innovative
Explain mediation-third party negotiation and arbitration : Explain mediation, third party negotiation, and arbitration. What are the differences between each?
Write a generic linked list class named AdaptiveList : Com S 228 Assignment: An Adaptive List. Write a generic linked list class named AdaptiveList. Your class must implement the java.util.List interface
Find probability that cars arrive at a particular dealership : From an inventory of 30 cars being shipped to a local automobile dealer, 4 are SUVs. What is the probability that if 4 cars arrive at a particular dealership.
List the components of the shoe : Explain why you removed those components and explain if it would create a new useful product or solve a problem
Least important for selling in the private label market : Rank each of following factors in order of most important to least important for selling in the private label market. Include short explanation for each ranking
Implications of his stores make these notifications : What are the ethical implications of his stores make these notifications?

Reviews

len1688978

10/24/2017 4:43:52 AM

Topic: Computer Science(data structure java). You are required to include, in your submission, the source code for each of the classes: A short template is given in package cs228hw3.zip. You need to write proper documentation with Javadoc for each method that you implement. Write your class so that its package name is edu.iastate.cs228.hw3. Your source ?les (.java ?les) will be placed in the directory edu/iastate/cs228/hw3 (Linux) or edu\iastate\cs228\hw3 (Windows), as de?ned by the package speci?ed above. Be sure to put down your name after the @author tag in each class source ?le. Your zip ?le should be named Firstname Lastname HW3.zip. You may submit a draft version of your code early to see if you have any submission problem with Blackboard Learn. We will grade only your latest submission.

Write a Review

JAVA Programming Questions & Answers

  Implement your client-server system

A detailed discussion of the methodology you used to implement your client-server system and a concise and detailed design for the client-server system

  Features of any programming language is recursion

One of the most useful features of any programming language is recursion and control structures, decisions and loops. Recursion and loop structures allow programs to repeat actions without duplicating code.

  Implement the nested loops

The user has also already entered a mystery number they want the following series to calculate based upon their current numbers (also relatively logical in size).

  Compares the two strings starting from index

Create a Simon says loop that compares the two strings starting from index 0. For each match, add one point to userScore.

  The access modifier of constructors should be

The access modifier of constructors should be

  Concurrent access to objects

This question asks about synchronizing methods for stack and queue objects. (a) Bounded stacks can be de?ned as objects, each containing an array of up to n items. Here is apseudocode for one form of stack class.

  How would you fix the program

How would you fix the program so it terminates when the user enters a Fahrenheit temperature less than the possible minimum temperature?

  Finally make a java test class in your test class you must

finally create a java test class. in your test class you should at a minimum a construct 200 instances of each subclass

  Inheriting from the jframe class

What is the difference between inheriting from the JFrame class and using a JFrame member variable?

  Program designs used in developing java applications

program designs used in developing Java applications

  Write a gui program that maintains a set of contacts

Write a GUI program that maintains a set of contacts. Each contact has name, address, and a list of phone numbers. This contacts should be be stored in a HashMap

  Build a class named roulette

CS 1400 - Hilton - Build a class named Roulette with a method named betOnce that takes a console Scanner and an integer as parameters

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