daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Node Insert(Node head,int data) {
  2.  
  3.     Node temp;
  4.     Node temp1 = head;
  5.    
  6.     if(head == null) //if empty
  7.     {
  8.         temp = new Node();
  9.         temp.data = data;
  10.         temp.next = null;
  11.         head = temp;
  12.        
  13.     }else
  14.     {
  15.         temp = new Node();
  16.         temp.data = data;
  17.         temp.next = null;
  18.         Node previous = new Node();
  19.        
  20.         while(temp1 != null)//traversing the list
  21.          {
  22.                 previous = temp1; //This is the LAST node
  23.                 temp1 = temp1.next; //strictly being used for traversal
  24.          }
  25.    
  26.          previous.next = temp;    
  27.     }
  28.     return head;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top