0

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??

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by NormR1
0

Have you taken a piece of paper and pencil and worked out the details on how the pointers change when working with a LL?

insert 1, how to accomidate

Where should the pointers be after a 1 is inserted?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.