DescendingSorts - if (numbers[scan] > numbers[min]) min...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // DescendingSorts.java Author: Lewis/Loftus // // Solution to Programming Project 6.3 // // Sorts in descending order. Demonstrates the selection sort // and insertion sort algorithms. //******************************************************************** / public class DescendingSorts { //----------------------------------------------------------------- // Sorts the specified array of integers in descending order // using the selection sort algorithm. //----------------------------------------------------------------- public static void selectionSort (int[] numbers) { int min, temp; for (int index = 0; index < numbers.length-1; index++) { min = index; for (int scan = index+1; scan < numbers.length; scan++)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (numbers[scan] > numbers[min]) min = scan; // Swap the values temp = numbers[min]; numbers[min] = numbers[index]; numbers[index] = temp; } } //-----------------------------------------------------------------// Sorts the specified array of integers in descending order // using the insertion sort algorithm. //-----------------------------------------------------------------public static void insertionSort (int numbers) { for (int index = 1; index < numbers.length; index++) { int key = numbers[index]; int position = index; // shift larger values to the right while (position > 0 && numbers[position-1] < key) { numbers[position] = numbers[position-1]; position--; } numbers[position] = key; } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online