Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

add element in the last in double linked list in java

void push_back(int newElement) {
  
  //1. allocate node
  Node newNode = new Node();
  
  //2. assign data element
  newNode.data = newElement;
  
  //3. assign null to the next and prev
  //   of the new node
  newNode.next = null; 
  newNode.prev = null;

  //4. Check the list is empty or not,
  //   if empty make the new node as head 
  if(head == null) {
    head = newNode;
  } else {
    
    //5. Else, traverse to the last node
    Node temp = new Node();
    temp = head;
    while(temp.next != null)
      temp = temp.next;
    
    //6. Adjust the links
    temp.next = newNode;
    newNode.prev = temp;
  }    
}
Comment

PREVIOUS NEXT
Code Example
Java :: java initialize class 
Java :: set top corner of shape radius programmatically android 
Java :: @override java example 
Java :: java first character string number 
Java :: Changing background color of selected item in recyclerview 
Java :: java foreach backwards 
Java :: labelled break statement in Java 
Java :: Java Longest String In String Array 
Java :: java split int 
Java :: how to convert kilometers to miles in java 
Java :: spring boot onetomany relationsion 
Java :: his version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.2 or newer. 
Java :: Quick Sort Java Implementation 
Java :: logging in java 
Java :: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId; 
Java :: java command to start jenkins 
Java :: jdk path 
Java :: java how to create an array with existing objects 
Java :: reverse java 
Java :: how to convert line into string java 
Java :: remove duplicates from string in java 
Java :: print symbol in pyramid shape in java 
Java :: android pass object to activity 
Java :: Java The Throw/Throws Keyword 
Java :: lowercase string java 
Java :: reading string after double in java 
Java :: FlutterSound.java uses or overrides a deprecated API. 
Java :: better way to check string on null and empty java 
Java :: java windowbuilder multiple monitors windowed mode 
Java :: lcm of two large positive integers java 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =