implements java.lang.Comparable<Nature>
to the very first line of your class Nature definition,
so that we can use it to sort objects in the linked list, which uses template class T.
Here is similar example code: ComparableItem.java
class MyLinkedList<T extends java.lang.Comparable<T>> extends LinkedList<T>
LinkedList<Nature> list = new LinkedList<Nature>();
MyLinkedList<Nature> list = new MyLinkedList<Nature>();
bubblesort()
method uses the bubblesort algorithm to sort the Nature
objects in the class LinkedList
, but the code is similar to the code in the class LinkedList's add(), get(), remove(), and toString() methods,
which loop through the nodes in the linked list.
In the bubblesort()
method, you need to swap the values stored in the data field of the adjacent Nature
objects (nodes that are right next to each other) that are out of order,
and you need to move from one Nature
object to the next Nature
object in your loop.
Depending on how your write your code, you will probably need to cast from datatype T to datatype Nature.
Then, use get() and set() methods to swap the data field values between two nodes that contain Nature objects that are out of order.
As an alternative to get() and set() methods, you could also write a swap() method in the class Nature to swap the datafield values
between two Nature objects.
object.method(parameters);
list.add(letter);
Item food = list3.get(2);
list.bubblesort();
ClassName.method(parameters);
Integer result2 = Factorials.recursive(number);
Sorting.bubbleSort(array);
You output will be similar, but not the same, as my output.
The formatting doesn't have to be exactly the same, but make sure it is neat and easy to read.
Here are details on the format() method, if you so wish to use it:
https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html
Or, in your CSV file, just make sure you leave extra spaces to evenly space the words.
Or, maybe you have your own unique way to do the formatting!
** Make sure you submit your CSV file with your assignment. **
Below is example output for using this input file as the first commandline argument: mammals.csv
Read from input file: mammals.csv Display MarineMammalsOfHawaii linked list after adding objects from the input file into a linked list: # name population length 1, Hawaiian monk seal 1100 2.40 2, humpback whale 10000 16.00 3, spinner dolphin 3351 2.35 4, common bottlenose dolphin 235 3.50 5, Risso's dolphin 85000 4.00 6, rough-toothed dolphin 150000 2.83 7, striped dolphin 2000000 2.60 8, pygmy killer whale 817 20.50 9, false killer whale 150 2.80 10, melon-headed whale 2950 3.00 11, short-finned pilot whale 8850 3.70 12, sperm whale 7082 17.30 13, dwarf sperm whale 19000 3.00 14, pygmy sperm whale 50 3.50 15, orca 50 10.70 16, Blainville's beaked whale 2200 5.00 17, Cuvier's beaked Whale 13000 8.30 18, pantropical spotted dolphin 3000000 2.50 Display MarineMammalsOfHawaii linked list after sorting linked list with bubblesort() method: # name population length 1, Blainville's beaked whale 2200 5.00 2, Cuvier's beaked Whale 13000 8.30 3, Hawaiian monk seal 1100 2.40 4, Risso's dolphin 85000 4.00 5, common bottlenose dolphin 235 3.50 6, dwarf sperm whale 19000 3.00 7, false killer whale 150 2.80 8, humpback whale 10000 16.00 9, melon-headed whale 2950 3.00 10, orca 50 10.70 11, pantropical spotted dolphin 3000000 2.50 12, pygmy killer whale 817 20.50 13, pygmy sperm whale 50 3.50 14, rough-toothed dolphin 150000 2.83 15, short-finned pilot whale 8850 3.70 16, sperm whale 7082 17.30 17, spinner dolphin 3351 2.35 18, striped dolphin 2000000 2.60