Java Reference
In-Depth Information
Enter list1:
Enter list2:
The merged list is 1 2 4 5 5 6 16 61 111
5 1 5 16 61 111
4 2 4 5 6
**6.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 . After the parti-
tion, the list becomes . Implement the method in a way that takes
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.
{5, 2, 9, 3, 6, 8}
{3, 2, 5, 9, 6, 8}
Enter list:
After the partition, the list is 9 1 5 1 10 61 11 16
8 10 1 5 16 61 9 11 1
*6.33
( Culture: Chinese Zodiac ) Simplify Listing 3.10 using an array of strings to store
the animal names.
***6.34
( Game: multiple Eight Queens solutions ) Exercise 6.22 finds one solution for the
Eight Queens problem. Write a program to count all possible solutions for the
Eight Queens problem and display all solutions.
 
 
Search WWH ::




Custom Search