|
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||
java.lang.Object | +--Bubble
Sample program for CISC 121, Fall 2000. This program reads a list of up to 10 integers, sorts them in ascending order, and prints them out. It uses the bubble sort algorithm.
Input: The integers to be sorted. These are read from the standard input. The program repeatedly prompts for an integer, then asks the user if s/he is done. This repeats until the user is done, or until the maximum number of integers is reached. If the user enters characters that are not integer format, the program will ask him/her to try again.
Output: The sorted list of integers, on the standard output.
Libraries Used: SavitchIn class for input.
Known Limitations: When the user answers the "are you done?" question, any character other than 'n' is considered a yes.
| Field Summary | |
private static int |
MAX_SIZE
The maximum number of integers the program will accept |
| Constructor Summary | |
Bubble()
|
|
| Method Summary | |
static void |
main(java.lang.String[] args)
the main method for the program. |
private static void |
printArray(int[] theArray,
int size)
prints an array of integers on the standard output, one per line. |
private static int |
readArray(int[] inputArray)
prompts for and reads an array of integers from the standard input. |
private static void |
sortArray(int[] theArray,
int size)
sorts an array of integers in ascending order using the "bubble sort" algorithm. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private static final int MAX_SIZE
| Constructor Detail |
public Bubble()
| Method Detail |
public static void main(java.lang.String[] args)
args - The command-line arguments. Not used in this program,
but required by Java
private static void printArray(int[] theArray,
int size)
assumptions: size is not negative, and the array has at least size elements
theArray - the array to be printedsize - the number of elements in the array to be printedprivate static int readArray(int[] inputArray)
Limitation: If the user answers the "are you done?" question with any character but a lower-case 'n', it is considered a yes.
inputArray - the array into which the integers are read
private static void sortArray(int[] theArray,
int size)
assumptions:
1. size is not negative
2. the array has least size elements
theArray - the array to be sortedsize - the number of elements in the array to be sorted
|
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||