Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and implement a version of selection sort (from Chapter 10 code is below) that operates on a linked list of nodes that each contain

Design and implement a version of selection sort (from

Chapter 10 code is below) that operates on a linked list of nodes that each

contain an integer.

//********************************************************************

// Sorting.java Author: Lewis/Loftus

//

// Demonstrates the selection sort and insertion sort algorithms.

//********************************************************************

public class Sorting

{

//-----------------------------------------------------------------

// Sorts the specified array of objects using the selection

// sort algorithm.

//-----------------------------------------------------------------

public static void selectionSort(Comparable[] list)

{

int min;

Comparable temp;

for (int index = 0; index < list.length-1; index++)

{

min = index;

for (int scan = index+1; scan < list.length; scan++)

if (list[scan].compareTo(list[min]) < 0)

min = scan;

// Swap the values

temp = list[min];

list[min] = list[index];

list[index] = temp;

}

}

//-----------------------------------------------------------------

// Sorts the specified array of objects using the insertion

// sort algorithm.

//-----------------------------------------------------------------

public static void insertionSort(Comparable[] list)

{

for (int index = 1; index < list.length; index++)

{

Comparable key = list[index];

int position = index;

// Shift larger values to the right

while (position > 0 && key.compareTo(list[position-1]) < 0)

{

list[position] = list[position-1];

position--;

}

list[position] = key;

}

}

}

in java please show output

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago