Question
JAVA Create an ORDERED linked list defined as: public class OrderedLinkedList { private LinkedListNode head_of_list = null; private LinkedListNode tail_of_list = null; private int count
JAVA
Create an ORDERED linked list defined as:
public class OrderedLinkedList
Code the following methods in OrderedLinkedList:
public boolean add(E e). Add an element to the list. The element is inserted into the correct position in the list maintaining low to high sort order. Returns true.
public int size(). Returns number of elements currently in the list.
public E get(int index). Returns the element at index. Throws IndexOutOfBoundsException if index is invalid.
Remember, this is an ORDERED list so the add() method must keep the elements of the list stored in ascending order (low to high value). Implement an insertion sort algorithm as described in class.
public class LinkedListDriver { private static OrderedLinkedListlinked = new OrderedLinkedList (); public static void main(String[] args) { /** A list of most popular north american men names according to some website */ linked.add("James"); linked.add("David"); linked.add("Christopher"); linked.add("George"); linked.add("Ronald"); linked.add("John"); linked.add("Richard"); linked.add("Daniel"); linked.add("Kenneth"); linked.add("Anthony"); linked.add("Robert"); linked.add("Charles"); linked.add("Paul"); linked.add("Steven"); linked.add("Kevin"); linked.add("Michael"); linked.add("Joseph"); linked.add("Mark"); linked.add("Edward"); linked.add("Jason"); linked.add("William"); linked.add("Thomas"); linked.add("Donald"); linked.add("Brian"); linked.add("Jeff"); /** A list of most popular north american women names according to some website */ linked.add("Mary"); linked.add("Jennifer"); linked.add("Lisa"); linked.add("Sandra"); linked.add("Michelle"); linked.add("Patricia"); linked.add("Maria"); linked.add("Nancy"); linked.add("Donna"); linked.add("Laura"); linked.add("Linda"); linked.add("Susan"); linked.add("Karen"); linked.add("Carol"); linked.add("Sarah"); linked.add("Barbara"); linked.add("Margaret"); linked.add("Betty"); linked.add("Ruth"); linked.add("Kimberly"); linked.add("Elizabeth"); linked.add("Dorothy"); linked.add("Helen"); linked.add("Sharon"); linked.add("Deborah"); /* print the names. Should come out as alphabetical */ for( int i=0; i
Note: code must use a linked list using insertion sort technique.
JAVA
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started