Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method that takes a linked list of integers and rearranges the nodes so that the integers stored are sorted into the order of

Write a method that takes a linked list of integers and rearranges the nodes so that the integers stored are sorted into the order of smallest to largest, with the smallest integer in the node at the head of the list. Your method should preserve repetitions of integers. If the original list had any integers occurring more than once, then the changed list will have the same number of each integer. 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 in this list are sorted from smallest to // largest. The original linked list is no longer available Your method will implement the following algorithm (which is often called selection sort): The algorithm 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 smallest 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 operator since it is just moving nodes from one list to another (not creating new nodes). 2 Create a GUI application to test your method. Your application should allow the user to specify the required length of the linked list. Then, the program uses random numbers (generated between 1, 100) to create the list with the specified length and display it to the user. Finally, the program should display the sorted list.

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

8-16 Describe some of the weaknesses exploited by malware.

Answered: 1 week ago