2004 BHCSI Introductory Java Homework Assignment #10: Sorting Assigned: Tuesday 7/20/04

advertisement
2004 BHCSI Introductory Java
Homework Assignment #10: Sorting
Assigned: Tuesday 7/20/04
Due: Tuesday 7/20/04
Objective:
In this assignment you will gain experience with sorting and using arrays.
Part A:
Ask the user for five random integers and store them in an array. Next run an Insertion
Sort on your integer array. You may use a single integer variable to store a temporary
value, but you may not use a second array. Once the array is sorted, print it out in order
(smallest to largest).
Example A:
Please enter your first number:
46
Please enter your second number:
68
Please enter your third number:
23
Please enter your fourth number:
11
Please enter your fifth number:
52
Smallest to largest your numbers would read…
11, 23, 46, 52, 68
Part B:
Repeat the exercise in part A, however this time use strings instead of integers. You will
ask the user to input five names. Next you will sort those names in alphabetical order.
The limitations from Part A still apply, once you are finished print out the names in
alphabetical order.
Example B:
Please enter your first name:
Adam
Please enter your second name:
Josh
Please enter your third name:
Wolfgang
Please enter your fourth name:
Vladimir
Please enter your fifth name:
Guy
In alphabetical order your names would read…
Adam, Guy, Josh, Vladimir, Wolfgang
If you have extra time, attempt to implement Selection Sort.
Download