Reference based linked list Node question.
Say I have a something like this;
char[] charArray = getCharArray();
int arraySize =100000;
Node[] person =new Node[arraySize];
and
for (int i = 0; i < person.length; i++){
person[i] =new Node(new Person(getNames(arraySize,charArray),randomAge(),randomIncome()));
}
What I have to do is search through the array "person" and delete any objects which have the same value for "name", the getName() method which is called in the for loop calls generates a random name.
I have to make sure duplicate names don't exisist in the array.
Im not really sure how to access and check the type of object in the Node array, the stored objects are of type "Person" and has data fields for name,age and income.
Someone please help!
Ta!
[1088 byte] By [
SpartanNZa] at [2007-11-27 2:25:51]

I'm not totally sure what you mean, but if you want to delete double values, there is no faster way then to use a nested loop afaik.
something like this:
for( int i = 0; i < person.length(); i++)
{
for( int j = 0; i < person.length(); j ++)
{
if( person[i].getName().equals(person[j].getName()))
{
//Duplicate !
}
}
}
It is not exactly what you asked for but it might help you in the right direction.
for (int i = 0 ; i < person.length ; i++)
for (int j = i ; j < person.length ; j++)
if (person[j] != null)
if (person[i].getName().compareTo(person[j].getName()) == 0)
person[j] = null;
notice that it's the very basic way of doing it, but not a really good one since you will have null pointers in your array if there are dups in the list
the smart way when you want values with no dups is to use a Set
see http://java.sun.com/docs/books/tutorial/collections/interfaces/set.html
for( int i = 0; i < person.length(); i++)
{
for( int j = 0; i < person.length(); j ++)
{
if( person[i].getName().equals(person[j].getName()))
{
StringBuffer sB = new StringBuffer();
sB.append( person[i].getName());
sB.append( j );
person[j].setName( sB.toString());
}
}
}
This way if it finds the same name, it will give the same name a different number behind it.
So if you have
Name: Sam Age: 21
Name: Sam Age: 35
Will become:
Name: Sam Age: 21
Name: Sam1 Age: 35