Hello,
I wrote an add method but for some reason it does not add more than 3 values. Could anyone tell me why?
here is my method:
public void addValue(int value) {
IntNode cur = head;
IntNode prev = cur;
IntNode t = new IntNode(value);
if (value <= cur.data){ // if the value of the new node t is greater then the value of previos node
t.link =head;
head =t;
}
else{
while(value > cur.data){
cur = cur.link;
}
t.link = cur;
prev.link = t;
}
}
Thank you