{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW5 - -HW#5 SPECS CS108 SPRING 2009-BIN SORT =...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
---------------------------------------------------------------------- HW#5 SPECS CS108, SPRING 2009 ---------------------------------------------------------------------- BIN SORT ======== BACKGROUND: ----------- There are many procedures for "sorting" a data set (arranging its items 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 that we 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 4 numerical 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 digit in the "tens" position instead. (If there is no explicit digit in the tens position, 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.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8. Repeat StoM. 9. Repeat MtoS, but transfer based on the digit in "thousands" position. 10. Repeat StoM. 11. Since your data items were assumed to have 4 digits maximum, then you only needed to do 4 "MtoS StoM" routines. So, you can stop now.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern