I have a problem with implementing the following:
Polygon p = new Polygon();
Polygon p2 = new Polygon();
p.setNext( p2 );
Polygon p3 = new Polygon();
Polygon p4 = new Polygon();
p3.setNext( p4);
Polygon p5 = new Polygon();
p4.setNext( p5);
//Now add the second list to the first one
p.setNext( p3 );
int i = 0;
while( p.next != null)
{
i++;
p = p.next;
}
System.out.println( i );
It seems that after inserting p3 the list stops.
Here is the code for the setNext method:
public void setNext( Polygon pe )
{
if( pe == null)
{
// next = null;
return;
}
Polygon cur = next;
Polygon prev = next;
while ( cur != null )
{
prev = cur;
cur = cur.next;
}
pe.next = cur;
if ( cur == next )
{
next = pe;
} else
{
prev.next = pe;
}
}
I think there should be the problem but only i don’t see it 
thanks in advance
?