Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Working with ChainSort.java apply incrementalInsertionSort algorithm to work with a linked chain instead of an array and implement a Shell sort for a linked chain.

  1. Working with ChainSort.java apply incrementalInsertionSort algorithm to work with a linked chain instead of an array and implement a Shell sort for a linked chain. The skeleton of the application is provided.
    1. Before calling incrementalInsertionSort method, set the previous pointers to create the appropriate sub-chains as shown in the picture below:

  1. During the sorting process, replace appropriate data without changing the next pointers.
public class ChainSort> { private Node firstNode; // reference to first node public ChainSort() { this.firstNode = null; } public void display() { Node currentNode = this.firstNode; while (currentNode != null) { System.out.print(currentNode.data + " "); currentNode = currentNode.next; } System.out.println(); } // end display public boolean isEmpty() { return this.firstNode == null; } // end isEmpty public void addToBeginning(T newEntry) { Node newNode = new Node<>(newEntry); newNode.next = this.firstNode; this.firstNode = newNode; } // end addToBeginning public void shellSort(int chainSize) { //TODO Project3   // for each space // create sub-chains: // set previousNode to the first node in the chain // set currentNode to the first node in the chain // with a for loop traverse nodes space times using currentNode // to find the second node of the first sub-chain // // with a while loop set up backward links for all sub-chains: // set currentNode's previous pointer to the previousNode // set previousNode to its next node and do the same with the currentNode // // call incrementalInsertionSort } // end shellSort /**  * Task: Sorts equally spaced elements of a linked chain into  * ascending order. Sub-chains created with a use of previous.  *  * @param space the space between the nodes of the  * elements to sort  */  private void incrementalInsertionSort( int space) { //TODO Project3   // when sorting do not change pointers - simply swap the data if needed } // end incrementalInsertionSort 

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Describe the types of power that effective leaders employ

Answered: 1 week ago