CSE 331 Homework 0: Course Survey and Paper Programming Exercise
Due Friday, June 26 at 11:59pm.
Part 1: Brief survey
Please fill out this Google form survey.
Part 2: Programming on paper
For this part, please find a blank sheet of paper and a writing utensil. Please write a Java method that solves the problem below. This will be graded on completion/effort only. Do not compile or test your program on a computer. Do not use external resources such as web searches or AI to help you with this problem. Since you do not have access to a compiler or normal reference materials, you will not lose points for minor syntax/formatting errors. Just try to make it clear what you were trying to do.
/**
* Reorder the elements of the given array so that all the negative numbers come
* first, followed by all the zeros, followed by all the positive numbers.
*
* For example, if, before the method runs, the array stores
* [5, -1, 0, -1, 0, 5, -2, 7]
* then, after the method runs, the array might store
* [-1, -1, -2, 0, 0, 5, 5, 7]
* or
* [-1, -2, -1, 0, 0, 7, 5, 5]
* or any other ordering of the negatives amongst themselves and postitives
* amongst themselves.
*
* Notice how any order amongst the negative elements is allowed, as long as all
* negative elements come before the zeros. Similarly, any order of positive
* elements is allowed as long as they come after the zeros.
*
* You may assume the array is not null.
*/
void kindaSort(int[] a) {
// your code here
}
You should try your best to make sure your code is correct, even though you did not compile or test it.
If you like, you may write swap(a, i, j); to mean "swap elements at indices i
and j of array a".
If possible, your code should run in linear time in the length of a. (Since
this is graded on completion/effort, you will not lose points if your code is
slower than linear time.)
Even better, if possible, your code should make a single pass over the array. Again you will not lose points for not meeting this requirement.
The staff solution is approximately 15 lines of code not including the starter code or blank lines or comments.
Take a picture of your sheet of paper and upload it to Gradescope "HW0 programming on paper".
Please do not spend more than 1 hour on this part. If you get to the end of 1 hour and are not done yet, write "I spent 1 hour on this, and this is what I have so far" and turn it in. You will receive full credit for a good faith attempt.