Im having trouble implementing my own ordered linked list from scratch.
public class LinkedList{
Node head,tail;
public LinkedList(){
head=tail=null;
}
public LinkedList(Node node){
this.head=new Node(node.num);
this.tail=new Node(node.num);
}
public static void main(String[] args){
LinkedList list=new LinkedList();
list.insert(new Node(7));
list.insert(new Node(3));
}
public void insert(Node node){
if(head==null){
head=node;
tail=node;
}
else{
if(node.num<head.num){
}
}
}
}
my trouble is lets say i want to insert 7 then 3 like above;
7 is the head and tail. then 3 < 7 so i need to make the head point to 3, tail to 7.
but then insert 1, how to accomidate??