This may be pretty elementary to some of you, but I've tried to do this
and can only get the remove to happen for one pair of duplicates. Can
someone help me with what i'm doing wrong?
public void insertionSort()
{
int in, out;
int j=0;
long key =-1;
for(out=1; out<nElems; out++) // out is dividing line
{
long temp = a[out];
// remove marked item
in = out; // start shifts at out
if(a[in-1]==temp)
temp=key;
while(in>0 && a[in-1] >= temp) // until one is smaller,
{
a[in] = a[in-1]; // shift item to right
--in; // go left one position
}
a[in] = temp; // insert marked item
} // end for
delete(key);
} // end insertionSort()
public boolean delete(long value)
{
int j;
for(j=0; j<nElems; j++) // look for it
if( value == a[j] )
break;
if(j==nElems) // can't find it
return false;
else // found it
{
for(int k=j; k<nElems; k++) // move higher ones down
a[k] = a[k+1];
nElems--; // decrement size
return true;
}
} // end delete()
Thanks in advance...
Heiner K?cker - 12 Feb 2005 12:40 GMT
Max Santelle
> This may be pretty elementary to some of you, but I've tried to do this
> and can only get the remove to happen for one pair of duplicates. Can
> someone help me with what i'm doing wrong?
Is TreeSet not useful for you?
Simple use Long objects as keys instead long values.
Heiner Kuecker
Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de
Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html
Domain Specific Languages http://www.heinerkuecker.de/DomainParser.html
Max Santelle - 13 Feb 2005 05:52 GMT
I'm just learning how to program using java, so I am not up to Trees or
TreeSets yet.
But thanks for replying!
PerfectDayToChaseTornados - 13 Feb 2005 20:04 GMT
| I'm just learning how to program using java, so I am not up to Trees or
| TreeSets yet.
| But thanks for replying!
Heiner is right, a Set will not allow duplicates. It should simplify your
problem :-)

Signature
-P
"Programs that are hard to read are hard to modify.
Programs that have duplicated logic are hard to modify.
Programs with complex conditional logic are hard to modify"
( Kent Beck)