Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(reverse linked list). This static method shall have one parameter that is a reference for a linked list of integers and shall return ahead reference

(reverse linked list). This static method shall have one parameter that is a reference for a linked list of integers and shall return ahead reference to a linked list of integers in the reverse order of the original list. Do not create any new nodes to do this. Write a demo program for this method. The argument to the method within the Demo program should be a reference to an IntNode, not a reference to a class that represents a linked list.

Use the books IntNode.java code. Do not use an array or any other data structure to hold the values in the list. Do not copy any data from the nodes.

Write a method with one parameter that is a head reference for a linked list of integers. The method creates a new list that has the same elements as the original list but in the reverse order. The method returns a head reference for the new list. integers, but your method should still work if you replace the integer type with any other type for which the less-than operation is defined. Use the following specification:

IntNode listSort(IntNode head)

// Postcondition: The return value is a head

// reference of a linked list with exactly the

// same entries as the original list (including

// repetitions, if any), but the entries 11 in this list are sorted from smallest to

// largest. The original linked list is no longer

// available.

Your method will implement the following algo- rithm (which is often called selection sort): The al- gorithm removes nodes one at a time from the original list and adds the nodes to a second list until all the nodes have been moved to the second list. The second list will then be sorted.

// Pseudocode for selection sort: while (the first list still has some nodes)

{

1. Find the node with the largest element of all the nodes in the first list.

2. Remove this node from the first list.

3. Add this node at the head of the second list.

}

Note that your method will move entire nodes, not just elements, to the second list. Thus, the first list will get shorter and shorter until it is an empty list. Your method should not need to use the new opera- tor since it is just moving nodes from one list to an- other (not creating new nodes).

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

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions

Question

2. Does your tone of voice vary with different students?

Answered: 1 week ago

Question

c. What is the most likely value for X?

Answered: 1 week ago