I have a linked list of integers. When I insert a new Node I need to insert it not at the end, but in oder... i.e. 2, 4, 5, 8, 11, 12, 33, 55, 58, 102, etc. I don't think I am inserting it in the correct position. Do see what Im doing wrong?
Node newNode = new Node(someInt);
Node current = head;
for(int i=0; i<count; i++){
if(current == tail && tail.data < someInt){
tail.next = newNode;
}
if(current.data < someInt && current.next.data >= someInt){
newNode.next = current.next;
current.next = newNode;
}
}