Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 { private LinkedListNode head_of_list = null; private LinkedListNode tail_of_list = null; private int count = 0; } public class LinkedListNode { public E obj; public LinkedListNode next; }

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 OrderedLinkedList linked = 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions