L12b

Due by the end of this meeting

Starter Files:


SUBMIT   /   Submission Summary

Heap Sort

Activity
I have provided you with a version of the program HeapSort from the sample code. This version reads in an array of String values instead of generating an array of int values. It also been modified to print out fewer intermediate steps.

Revise the methods sort, percolateDown and largerChild so that the program can sort the array of String.

Activate the command to sort the array.

Test your program with the following names:

Mal
Zoe
Kaylee
Wash
Jayne
Inara
Simon
River
Book

Here is what you should see (with the blue bits being the input you provide:

Heap Sort --------- This program uses heap sort to sort an array. How long should I make the list? 9 Enter item #0: Mal Enter item #1: Zoe Enter item #2: Kaylee Enter item #3: Wash Enter item #4: Jayne Enter item #5: Inara Enter item #6: Simon Enter item #7: River Enter item #8: Book Array values before sorting: [Mal, Zoe, Kaylee, Wash, Jayne, Inara, Simon, River, Book] ...Press ENTER... Changing the list into a max-heap: Shifting Wash down... Shifting Kaylee down... Shifting Zoe down... Shifting Mal down... Array values as a max-heap: [Zoe, Wash, Simon, River, Jayne, Inara, Kaylee, Mal, Book] ...Press ENTER... Removing front items to back: Moving Zoe to the back... Moving Wash to the back... Moving Simon to the back... Moving River to the back... Moving Mal to the back... Moving Kaylee to the back... Moving Jayne to the back... Moving Inara to the back... Array values after sorting: [Book, Inara, Jayne, Kaylee, Mal, River, Simon, Wash, Zoe] ...Press ENTER...
Your grade will be based on the following rubric:

Submit this/these files:


SUBMIT   /   Submission Summary