CIS 160 - Implementing a sort

Objectives

  • Process elements of an array
  • Implement an array sort

Program overview

You get most of the code for this project. All you have to do is implement the supplied sorting algorithm. Other sorting algorithms will not be accepted and automatically get 0 points. Make sure you update the documentation comments, write the sort method, and uncomment the call to sort in main(String[]).

It is considered cheating to copy work. Problems may be discussed, but not copied.

Your starting code for this assignment is available here: StickySort.java.txt

Requirements/algorithm

  1. A method named sort which takes an integer array as its only argument, and sorts that array into ascending order. Nothing is returned from this method.
  2. The algorithm you are REQUIRED to implement in sort is: start at index 0 in the array while the index is referring to an element that comes before the last element of the array if the array elements at the index and the next location are in proper order move forward by incrementing the index otherwise swap the array elements that are out of order if the index won't go negative, decrement it
  3. Uncomment the call to sort within main(String[]) and eliminate the comments in the source code telling you to uncomment it.
  4. Update the beginning documentation to include your name, the date, and what you modified in the program.

Sample run

The original array is not sorted: 94 33 05 91 32 72 59 09 99 80 70 86 66 40 58 97 46 11 75 82 The result array is sorted: 05 09 11 32 33 40 46 58 59 66 70 72 75 80 82 86 91 94 97 99

Rubric

  • 2 points for updating the documentation comments
  • 3 points for following the programming style discussed in class and demonstrated in sample programs (proper indentation, spaces for indentation, variable names start with lowercase letter, class names start with uppercase letter, etc.)
  • 35 points for properly implementing the required algorithm