Java Reference
In-Depth Information
Implement the method in a way that takes at most list1.length + list2.
length comparisons. Write a test program that prompts the user to enter two
sorted lists and displays the merged list. Here is a sample run. Note that the first
number in the input indicates the number of the elements in the list. This number
is not part of the list.
Enter list1: 5 1 5 16 61 111
Enter list2: 4 2 4 5 6
The merged list is 1 2 4 5 5 6 16 61 111
**7.32
( Partition of a list ) Write the following method that partitions the list using the
first element, called a pivot .
public static int partition( int [] list)
After the partition, the elements in the list are rearranged so that all the elements
before the pivot are less than or equal to the pivot and the elements after the pivot
are greater than the pivot. The method returns the index where the pivot is located
in the new list. For example, suppose the list is {5,2,9,3,6,8}. After the parti-
tion, the list becomes {3, 2, 5, 9, 6, 8}. Implement the method in a way that takes
at most list.length comparisons. Write a test program that prompts the user
to enter a list and displays the list after the partition. Here is a sample run. Note
that the first number in the input indicates the number of the elements in the list.
This number is not part of the list.
Enter list: 8 10 1 5 16 61 9 11 1
After the partition, the list is 9 1 5 1 10 61 11 16
*7.33
( Culture: Chinese Zodiac ) Simplify ListingĀ 3.9 using an array of strings to store
the animal names.
**7.34
( Sort characters in a string ) Write a method that returns a sorted string using the
following header:
public static String sort(String s)
For example, sort("acb") returns abc .
Write a test program that prompts the user to enter a string and displays the sorted
string.
***7.35
( Game: hangman ) Write a hangman game that randomly generates a word and
prompts the user to guess one letter at a time, as shown in the sample run. Each
letter in the word is displayed as an asterisk. When the user makes a correct
guess, the actual letter is then displayed. When the user finishes a word, display
 
 
Search WWH ::




Custom Search