This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: HW#5 SPECSCS108, SPRING 2009BIN SORT========BACKGROUND:There are many procedures for "sorting" a data set (arranging itsitems so that they are ordered from smallest to largest):Bin Sort, Quick Sort, Insertion Sort, Merge Sort, Heap Sort, etc.For HW#5, you will implement a "Bin Sort".You will need to use "stacks" (e.g., the "StackV" class thatwe dicussed and coded in lecture).BIN SORT:1. Consider a "main bin" (bucket), which acts like a "stack".Consider 9 "sort bins", i.e. sort bin#0 to sort bin#9, each is like a stack.2. "Push" each of your (unsorted) data items onto the "main bin".For HW#5, assume that each data item will be no more than 4numerical digits long, i.e. 0 to 9999.3. MtoS procedure:For each data item in the main bin, pop it off,then look at the digit in the "ones" position (ie, rightmost digit).Push the data item onto the sort bin whose number matches the digit.(E.g., if the data item is "456", then digit "6" is in the ones position,therefore push the "456" onto sort bin#6.)4. StoM procedure:For each data item in sort bin#9, pop it off, then push it onto main bin.Repeat that for sort bin#8, then sort bin#7, then sort bin#6, etc.,then sort bin#0.5. Repeat the MtoS procedure, but transfer data items based on the digitin the "tens" position instead. (If there is no explicit digit in the tensposition, then the digit is 0. E.g., because 1 is the same number as 0001.)6. Repeat the StoM procedure.7. Repeat MtoS, but transfer based on the digit in the "hundreds" position.8. Repeat StoM.9. Repeat MtoS, but transfer based on the digit in "thousands" position.10. Repeat StoM....
View
Full
Document
This note was uploaded on 08/17/2011 for the course CS 108 taught by Professor Ivanbajic during the Spring '09 term at San Diego.
 Spring '09
 IvanBajic
 Insertion Sort, Quick Sort

Click to edit the document details