Look up how to do quicksort. Write a method to do quicksort of an array of names.

What will be an ideal response?


```
/**
*Method to do a qui c k s o r t on the ar ray
*/
public void qui ckSor t ( )
{
// check i f the ar ray i s n u l l or has a l e n g t h of 0 or 1
i f ( a == nul l j j a . l eng th <= 1)
return ;
el se
{
// p i c k a p i v o t inde x
int pivot Index = a . l eng th / 2 ;
// g e t the p i v o t v a lue
St r ing pivotValue = a [ pivot Index ] ;
// d i s t r i b u t e a l l v a l u e s < the p i v o t inde x
Li s t l e s s = new Ar rayLi s t( ) ;
Li s t more = new Ar rayLi s t( ) ;
for ( int i = 0 ; i < pivot Index ; i++)
{
i f ( a [ i ] . compareTo ( pivotValue ) < 0)
l e s s . add ( a [ i ] ) ;
el se
more . add ( a [ i ] ) ;
}
// d i s t r i b u t e a l l v a l u e s > than the p i v o t inde x
for ( int i = pivot Index + 1 ; i < a . l eng th ; i++)
{
i f ( a [ i ] . compareTo ( pivotValue ) < 0)
l e s s . add ( a [ i ] ) ;
el se
more . add ( a [ i ] ) ;
}
// c r e a t e two new St r ingAr r a ySo r t e r s and s o r t t h e s e
St r ing [ ] l e s sAr r a y = l e s s . toArray (new St r ing [ l e s s . s i z e ( ) ] ) ;
St r ingAr r aySo r t e r s o r t e rLe s s = new St r ingAr r aySo r t e r ( l e s sAr r a y ) ;
s o r t e rLe s s . qui ckSor t ( ) ;
St r ing [ ] moreArray = more . toArray (new St r ing [more . s i z e ( ) ] ) ;
St r ingAr r aySo r t e r sor t e rMor e = new St r ingAr r aySo r t e r (moreArray ) ;
sor t e rMor e . qui ckSor t ( ) ;
// put the s o r t e d e l ement s back in the ar ray
int i = 0 ;
for ( ; i < l e s sAr r a y . l ength ; i++)
{
a [ i ] = l e s sAr r a y [ i ] ;
}
a [ i++] = pivotValue ;
for ( int j = 0 ; j < moreArray . l ength ; j++)
{
a [ i++] = moreArray [ j ] ;
}
}
}
```

Computer Science & Information Technology

You might also like to view...

When you need to build a separate section of a Web site, it is usually best to create a separate folder within the site's root folder to hold the files for that section.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Separation of duties is when more than one person is required to complete a task

Indicate whether the statement is true or false

Computer Science & Information Technology

Crown Manufacturing's purchasing system is directly linked to the order entry systems of their key vendors. This is an example of

a. public network services b. electronic data interchange (EDI) c. telecommuting d. electronic document distribution

Computer Science & Information Technology

_____ is an effective troubleshooting tool during the development process and adds a valuable level of professionalism to a work.?

A. ?Optimization B. ?Normalization C. ?Validation D. ?Encryption

Computer Science & Information Technology