A classmate of yours has coded the following version of selectionSort().Will it work? Explain.

```
/**
* Sort the array elements in ascending order
* using selection sort.
* @param a the array of Objects to sort
* @throws NullPointerException if a is null
*/
static void selectionSort( Object[] a ) {
if ( a == null )
throw new NullPointerException();
// while the size of the unsorted part is > 1
for ( int unsortedSize = a.length; unsortedSize > 1; unsortedSize-- ) {
// find the position of the largest
// element in the unsorted section
int maxPos = 0;
for ( int pos = 1; pos < unsortedSize; pos++ )
if ( a[pos] > a[maxPos] )
maxPos = pos;
// postcondition: maxPos is the position
// of the largest element in the unsorted
// part of the array
// Swap largest value with the last value
// in the unsorted part
Object temp = a[unsortedSize – 1];
a[unsortedSize – 1] = a[maxPos];
a[maxPos] = temp;
}
}

```


No, the comparison of objects in the if-statement is comparing the object references, not the object values.

Computer Science & Information Technology

You might also like to view...

A(n) ____ object is a temporary cache storage for data retrieved from a data source.

A. Data Source B. Cache C. Database D. DataSet

Computer Science & Information Technology

Case WD 2-1Julia has written a 30-page report on Best Childcare Practices for one of her college courses.  She wants to rearrange several areas of text so that the report flows better and will make more sense to the reader.Julia now wants to move a set of characters. She would first click to the left of the first character, press and hold ____, and then click to the right of the last character she wants to select.

A. TAB B. ALT C. F3 D. SHIFT

Computer Science & Information Technology

A(n) ____ number contains decimal places.

A. integer B. floating-point C. infinite D. undefined

Computer Science & Information Technology

____ software finds and removes malware from your computer and scans incoming and outgoing email messages to identify threats.

A. Antivirus B. Program C. Application D. Firewall

Computer Science & Information Technology