Java Reference
In-Depth Information
12,000,000, 14,000,000, 16,000,000, and 18,000,000 using the algorithms in
Listings 22.5-22.7. Your program should print a table like this:
8000000
10000000
12000000
14000000
16000000
18000000
Listing 22.5
Listing 22.6
Listing 22.7
**22.15
( Geometry: non-cross polygon ) Write a program that enables the user to add/
remove points by clicking the left/right mouse button, and displays a non-
crossed polygon that links all the points, as shown in Figure 22.11a. A polygon
is crossed if two or more sides intersect, as shown in Figure 22.11b. Use the
following algorithm to construct a polygon from a set of points.
(a)
(b) Crossed polygon
F IGURE 22.11
(a) Programming Exercise22.15 displays a non-crossed polygon for a set of
points. (b) Two or more sides intersect in a crossed polygon.
Step 1: Given a set of points S , select the rightmost lowest
point p 0 in the set S .
Step 2: Sort the points in S angularly along the x -axis
with p 0 as the center. If there is a tie and two points have
the same angle, the one that is closer to p 0 is considered
greater. The points in S are now sorted as p 0 , p 1 , p 2 , ...,
p n-1 .
Step 3: The sorted points form a non-cross polygon.
**22.16
( Linear search animation ) Write a program that animates the linear search
algorithm. Create an array that consists of 20 distinct numbers from 1 to 20
in a random order. The array elements are displayed in a histogram, as shown
in Figure 22.12. You need to enter a search key in the text field. Clicking the
Step button causes the program to perform one comparison in the algorithm and
repaints the histogram with a bar indicating the search position. This button
also freezes the text field to prevent its value from being changed. When the
algorithm is finished, display the status in the label at the top of the border pane
to inform the user. Clicking the Reset button creates a new random array for a
new start. This button also makes the text field editable.
 
 
Search WWH ::




Custom Search