Skip to main content

Adding Node at the End of Linked List

Adding Node at the End of Linked List:-

The method takes two parameter one a head node of a linked list and other data too insert.


 public void addNodeEnd(Node head,int data)
 {
  if(head==null)
  {
   System.out.println("list is empty");
   return;
  }
 Node node=new Node(data);
 Node temp=head;
 while(temp.next!=null)
 {
  temp=temp.next;
 }
 temp.next=node;
 }

To Know the basic structure of the linked list click here


Comments

.

Popular posts from this blog

Insertion Sort in JAVA

What is insertion sort?

It is a sorting technique that is based on the partitioning of array into two parts like selection sort, sorted and unsorted.

The process is:-

compare adjacent elements.
if(left > right)
Swap the element
{
check for sorted array whether it is still in sort manner(put j=i and loop in until j is not equal to zero)
- No
check for if(right<left)
swap
do it until at the end of position.
}

Implementation:-

Underline eleemnts are part of sorted arrayinside main array loop 142710333519424 (141027333519424 (here sorted array is distorted hence sorting has been done inside the loop) inside sorted array loop101427333519424 inside main array loop101427333519424 inside main array loop 101427333519424 inside main array loop101427333519424 inside sorted array loop 101427193335424 inside sorted array loop 101419273335424 inside main array loop 101419273335424 inside main array loop 101419273335424 inside sorted array loop101419273343542 inside…