Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Implementation of a variation on the linked list idea that stores its data in two separate orders at once. That is, it stores data in the usual order, based on when it was added by the user.

At the same time, however, it keeps track of an ascending sorted order. To achieve this, it uses a Node class that comes with four separate references.To complete this assignment, you will do the following things (not necessarily in order):

Question 1. Write the constructor for the SortTraversableLinkedList. It should create the head and tail nodes, and set the size of the list to 0, as in a typical linked list.

Question 2. Write the methods used in Section One of the commented-out test code in Main. These methods should work as follows:

• The size() and toString() methods should work in exactly the way they do for normal linked lists, returning the number of elements and a String representation of the list (match the format in the sample output).

• The basic add() method should take in an element of type T and add it to the end of the list (just before the tail), using the next and prev links as usual. At the same time, it should re-arrange any prevSort and nextSort links so that they reflect the sorted order. Since the list class is restricted to Comparable types, you know that any objects that get added to the list will have a compareTo() method. You can use this fact to decide upon the right sorted order. (It should be a least-to-greatest, ascending sort.)

• The second add() method should take in an element of type T, along with an index position at which to add it. It should place the element at that position, using the usual next and prev links, and also re-arrange the other links for the proper sorted order. It should throw an IndexOutOfBoundsException if the given index is not in the proper range of values, just as in a normal linked list.

• The sortedToString() method should return a String that represents the list in its sorted order, again matching the format of the sample output.

When you are done, you should have a list structure that allows insertion of an object at any point in linear O(n) time (we no longer get constant-time O(1) addition to the end of the list, since we have to also re-arrange links to keep the sorted order correct). The trade-off for this extra bit of work here is that we never have to call a method in order to get the list in sorted order-instead, simply traversing the list using the second set of links gives us the sorted order without having to call any sorting algorithms, which can provide significant speed-ups down the road.

Question 3. Write the methods used in Section Two of Main:

• The get() method should work as for a normal linked-list, returning the value at a given position in the list, without changing the list at all, and throwing exceptions if the position requested does not exist.

• The getLeast() and getGreatest() methods should return the least and greatest value in the list, respectively. If you have implemented your list correctly, these methods will each run in constant O(1) time. If the list is empty, the methods should generate a NoSuchElementException.

Question 4. Write the methods used in Section Three of Main:

• The remove() method should work as for a normal linked-list, returning the value at a given position in the list, after removing it from the list, and throwing exceptions if the position requested does not exist.

• The removeLeast() and removeGreatest() methods should remove and return the least and greatest value in the list, respectively. If you have implemented your list correctly, these methods will each run in constant O(1) time. If the list is empty, the methods should generate a NoSuchElementException.

When you write these methods, be sure that you update all of the references required to keep both the insertion and sorted orders working in your list.

Question 5. Write the methods used in Section Four of Main. Each method should return the index of any given input value in the list (indices start at 0). The only differences between the two is that indexOf() should use the normal linked-list order, while sortedIndexOf() should use the sorting order (so that the least element is always at sorted index 0 and the greatest at size() - 1). Both methods should return value -1 if the element sought does not occur in the list at all.

Question 6. Write the methods used in Section Five of Main. To do this, you will have to make your list class properly Iterable and write two separate Iterator implementations inside it. The first one, returned by the usual iterator() method, should work as usual for a linked list, returning elements in the order they were inserted. The second one, returned by the sortedIterator() method, should use the ascending sorted order. Note: by default, the regular iterator will be used when using for-each looping. If you want to loop in sorted order, you will need to explicitly generate the special sorting iterator to do so.

Question 7. Write the methods used in Section Six of Main. Each of these will take in an array of the same type as the list, and return an array of the same type, containing all of its elements. As usual, the normal toArray() method will generate an array containing elements in the normal insertion order, whereas sortedToArray() will return an array containing elements in ascending sorted order. Note: you should not call any algorithms to actually sort any data to accomplish all this-you already have a list that can be put into an array in sorted order directly. Thus, both array conversion methods should run in linear O(n) time.

Java, Programming

  • Category:- Java
  • Reference No.:- M91221631
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Java

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As