I created this class with the method addVertex
:
public class Polygon {
private PointNode _startPoint;
public Polygon() {
_startPoint = null;
}
public boolean addVertex(Point p, int pos) {
PointNode next = _startPoint;
int i = 0;
while(i != pos){
if(next == null)
return false;
next = next.getNext();
i++;
}
next = new PointNode(p);
return true;
}
}
But the problem is that next
doesn't alias with _startPoint
and because of that I can only use the method when pos == 0
but if pos >= 1
then it always returns false even after I set a value in position 0 of the list I created.
Can someone tell me where the problem is?