| oogabooga |
22Sep2008 22:03 |
Re: Java:Insertion Sort
Your insertion sort should be more like this:
Code:
public static void insertion_sort()
{
for( int j = 1; j < accList.length; ++j )
{
for( int k = j - 1;
k >= 0 && accList[j].getAccountNum() < accList[k].getAccountNum();
--k )
{
accList[k+1] = accList[k];
}
accList[k + 1] = accList[j];
}
}
And your deleteAccount function should be more like this:
Code:
public static void deleteAccount( int acc_index )
{
for( int i = acc_index; i < accList.length - 1; ++i )
{
accList[i] = accList[i + 1];
}
// Now you must reduce the length of the accList array by one,
// i.e., the last element must be deleted from the array object.
// I do not know how that is done in Java.
// So you need to do what the following line says,
// but in the Java idiom.
delete( accList[accList.length - 1] );
}
|