Write the methods used in section two of main

Assignment Help JAVA Programming
Reference no: EM13681906

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.

Reference no: EM13681906

Questions Cloud

Determine the distance between the object and the image : An object is located 24.5 centimeter to the left of a thin converging lens that has focal length +12.1 centimeter. Find the distance between the object and the image
Determine what is the electric potential magnitude : The dipole moment of a water molecule is 6.04E-30 Cm. Find what is the electric potential magnitude 1.09 nm from a water molecule along the axis of the dipole
Determine what is the intensity of sound : Sound 1 has an intensity of 39 W/m2. Sound 2 has an intensity level that is 2 dB greater than the intensity level of sound 1. Determine What is the intensity of sound 2
Obtain the recoil velocity of the man relative to ice : Starting from rest, two skaters "push off" against each other on smooth level ice, where friction is negligible. One is a man and one is a woman. obtain the recoil velocity of the man relative to ice
Write the methods used in section two of main : 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.
Gordons functional health pattern : Gordon's Functional Health Pattern. You will develop questions for each of the health patterns to use as a family assessment guide as you find a family to assess.
Wire has a resistivity-what length of wire is required : A particular wire has a resistivity of 6.21×10-8 m and a cross-sectional area of 2.04 mm2. A length of this wire is to be utilized as a resistor that will develop 120 W of power when connected to a 6.50 V battery. What length of wire is required?
Return on sales and asset turnover : Current, debt-to-equity, return on sales, and asset turnover.
Voltage drop across current-carrying wire : Wires are not really ideal. The voltage drop across a current-carrying wire can be important unless the resistance of the wire is quite low. Presume a 40ft extension cord is being used to provide power to an electric lawn mower. The cord carries a 11..

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Build a thread system

Identify all Nachos classes that you will modify and where you plan to do you modifications - Identify all classes that you plan to implement and give the API for each class,

  Report the last letter of each word in the string

Write a sequence of Java statements that report the last letter of each word in the string.

  Write a method called makerow

Write a method called makeRow that is passed two arguments: an int and a String. It returns a String containing n copies of s, concatenated in a row. For instance, if we call the method with makeRow(5, "*"), the method returns *****.

  Returns the object with the largest measure

public static Measurable maximum(Measurable[] objects)that returns the object with the largest measure. Use that method to determine the country with the largest area from an array of

  Write a program in java that reads contents of two vectors

Write a program in Java that reads contents of two vectors, and then displays the sum of these two vectors. The program should prompt the user to enter the size of the vectors first.

  Integers as a parameter and returns the number

Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number the number of times the most frequently occurring integer

  Programming principles please help me doing my assignment i

please help me doing my assignment i have attached my assignment requirement document refer it and send me the solution

  Implement a thread for each creature representing a task

Implement a threads and a GUI interface using advanced Java Swing classes.

  A program that reads a four-digit number from the keyb

Write a program that reads a four-digit number from the keyboard as a string and then converts it into decimal. For example, if the input is 1100, the output should be 12. Hint: Break the string into characters and then convert each character to a va..

  Display at least the waiting at each floor

From the 1st floor, the elevator can only go in one direction - up. And from the 12th floor the elevator can only go in one direction - down.

  Design and implement a set of classes and interfaces and

design and implement a set of classes and interfaces and use them to evaluate the rtas resource requirements.nbspyour

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