Look up how to do an insertion sort. Write a method to do a insertion sort of an array of names. See the StringArraySorter class in the directory bookClass- esFinal.
What will be an ideal response?
```
/**
* Method to do an i n s e r t i o n s o r t on the ar ray
*/
public void i n s e r t i o n S o r t ( )
{
St r ing temp = nul l ;
int pos = 0 ;
// loop from second element on
for ( int i = 1 ; i < a . l eng th ; i++)
{
// save cur r ent v a lue at i and s e t p o s i t i o n to i
temp = a [ i ] ;
pos = i ;
// s h i f t r i g h t any l a r g e r e l ement s
while (0 < pos && temp . compareTo ( a [ pos ¡ 1 ] ) < 0)
{
a [ pos ] = a [ pos ¡ 1 ] ;
pos¡¡;
}
a [ pos ] = temp ;
this . pr intAr ray ( " a f t e r loop body when i = " + i ) ;
}
}
```
You might also like to view...
Which of the following describes a Quad Core processor?
A. A CPU with four direct channels to the FSB. B. Four CPU cores operating off one CPU package. C. A PC with four unique processors. D. A CPU with four cache memory locations.
A USB flash drive is a(n) input device.
Answer the following statement true (T) or false (F)