Inserting a Node in Linked List


public Node InsertInList(Node head,Node nodeToInsert,int position){
		if (head==null) return nodeToInsert;
		int size=length(head);
		if(position>size+1||position<1){
			System.out.println("Position invalid. Valid inputs are from 1 to"+(size+1));
			return head;
		}
		if (position==1){
			nodeToInsert.setNext(head);
			return nodeToInsert;
		}else{
			Node previousNode=head;
			int count=1;
			while(count
	

Leave a Reply

Your email address will not be published. Required fields are marked *