Java Reference
In-Depth Information
private static void interchange( int i, int j, double [] a)
{
double temp;
temp = a[i];
a[i] = a[j];
a[j] = temp; //original value of a[i]
}
}
5.
An array of random values would have the fastest run time, since it would divide
the array segments into approximately equal subarrays most of the time. The
other two cases would give approximately the same running time and would be
significantly slower, because the algorithms would always divide an array seg-
ment into very unequal size pieces, one piece with only one element and one
piece with the rest of the elements. It is ironic but true that our version of the
quick sort algorithms has its worst behavior on an already sorted array. There are
variations on the quick sort algorithms that perform well on a sorted array. For
example, choosing the middle element as the splitting value will give good per-
formance on an already sorted array. But, whatever splitting value you choose,
there will always be a few cases with slow running time.
Programming Projects
Many of these Programming Projects can be solved using AW's CodeMate.
To access these please go to: www.aw-bc.com/codemate .
1.
The UML diagram below describes a class named Movie . Implement this class in
Java and test it from a main method that creates several Movie objects. The
printDescription() method should output all member variables for the class.
Movie
-title: String
-minutes: int
-year: int
#price: double
+Movie(in String title, in int year, in double price)
+getTitle( ): String
+setTitle(in String newTitle)
+printDescription( )
The word “in” means the parameter is used to deliver data to the method.
Search WWH ::




Custom Search