Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

doubly linked list java add an element to the end

// Add a node at the end of the list
void append(int new_data)
{
    /* 1. allocate node
     * 2. put in the data */
    Node new_node = new Node(new_data);
 
    Node last = head; /* used in step 5*/
 
    /* 3. This new node is going to be the last node, so
     * make next of it as NULL*/
    new_node.next = null;
 
    /* 4. If the Linked List is empty, then make the new
     * node as head */
    if (head == null) {
        new_node.prev = null;
        head = new_node;
        return;
    }
 
    /* 5. Else traverse till the last node */
    while (last.next != null)
        last = last.next;
 
    /* 6. Change the next of last node */
    last.next = new_node;
 
    /* 7. Make last node as previous of new node */
    new_node.prev = last;
}
Comment

doubly linked list java add an element to the end

// Add a node at the end of the list
void append(int new_data)
{
    /* 1. allocate node
     * 2. put in the data */
    Node new_node = new Node(new_data);
 
    Node last = head; /* used in step 5*/
 
    /* 3. This new node is going to be the last node, so
     * make next of it as NULL*/
    new_node.next = null;
 
    /* 4. If the Linked List is empty, then make the new
     * node as head */
    if (head == null) {
        new_node.prev = null;
        head = new_node;
        return;
    }
 
    /* 5. Else traverse till the last node */
    while (last.next != null)
        last = last.next;
 
    /* 6. Change the next of last node */
    last.next = new_node;
 
    /* 7. Make last node as previous of new node */
    new_node.prev = last;
}
Comment

doubly linked list java add an element to the end

// Add a node at the end of the list
void append(int new_data)
{
    /* 1. allocate node
     * 2. put in the data */
    Node new_node = new Node(new_data);
 
    Node last = head; /* used in step 5*/
 
    /* 3. This new node is going to be the last node, so
     * make next of it as NULL*/
    new_node.next = null;
 
    /* 4. If the Linked List is empty, then make the new
     * node as head */
    if (head == null) {
        new_node.prev = null;
        head = new_node;
        return;
    }
 
    /* 5. Else traverse till the last node */
    while (last.next != null)
        last = last.next;
 
    /* 6. Change the next of last node */
    last.next = new_node;
 
    /* 7. Make last node as previous of new node */
    new_node.prev = last;
}
Comment

doubly linked list java add an element to the end

// Add a node at the end of the list
void append(int new_data)
{
    /* 1. allocate node
     * 2. put in the data */
    Node new_node = new Node(new_data);
 
    Node last = head; /* used in step 5*/
 
    /* 3. This new node is going to be the last node, so
     * make next of it as NULL*/
    new_node.next = null;
 
    /* 4. If the Linked List is empty, then make the new
     * node as head */
    if (head == null) {
        new_node.prev = null;
        head = new_node;
        return;
    }
 
    /* 5. Else traverse till the last node */
    while (last.next != null)
        last = last.next;
 
    /* 6. Change the next of last node */
    last.next = new_node;
 
    /* 7. Make last node as previous of new node */
    new_node.prev = last;
}
Comment

PREVIOUS NEXT
Code Example
Java :: quick way to get charAt 
Java :: nullpointerexception 
Java :: compare time in java 
Java :: java nested for loop 
Java :: executors java 
Java :: can abstract class have constructor 
Java :: install java 11 
Java :: remove part of string java 
Java :: java to kotlin tutorial 
Java :: rotate matrix in java 
Java :: java android join array list 
Java :: top easiest languages programming to learn 
Java :: java or cpp 
Java :: nested for loop java 
Java :: how to call child class method from parent class in java 
Java :: first and last element of array java 
Java :: how to change my file into binary data using java 
Java :: Mila Kunis 
Java :: java forcing user to input int 
Java :: in java write a code that suppose the following input is supplied to the program: 9 Then, the output should be: 12096 (99+999+9999+999) 
Sql :: mysql last 7 days including today 
Sql :: set password for postgres user ubuntu 
Sql :: check timezone of mysql database 
Sql :: oracle show grants on table 
Sql :: oracle enable job 
Sql :: oracle string length 
Sql :: sql server version query 
Sql :: mysql select random id from table 
Sql :: raise application error in oracle 
Sql :: change column name mysql command line 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =