Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add to the end of a linked list

typedef struct node{
    int value; //this is the value the node stores
    struct node *next; //this is the node the current node points to. this is how the nodes link
}node;

node *append(node *head, int val){
    node *tmp = head;
    node *createdNode = createNode(val);

    while(tmp->next != NULL){
        tmp = tmp->next;
    } 

    tmp->next = createdNode;
    return head;
}
Comment

adding an element to the end of a linked list java

class Node {
    Object data;
    Node next;
    Node(Object d,Node n) {
        data = d ;
        next = n ;
       }

   public static Node addLast(Node header, Object x) {
       // save the reference to the header so we can return it.
       Node ret = header;

       // check base case, header is null.
       if (header == null) {
           return new Node(x, null);
       }

       // loop until we find the end of the list
       while ((header.next != null)) {
           header = header.next;
       }

       // set the new node to the Object x, next will be null.
       header.next = new Node(x, null);
       return ret;
   }
}
Comment

PREVIOUS NEXT
Code Example
Java :: sorting algorithms in java 
Java :: how to check if array is full java 
Java :: how to call a void method from another class in java 
Java :: java resto 
Java :: enum to string java 
Java :: convert python code to java 
Java :: finding min and max from given number in java 
Java :: result set methods 
Java :: how to import borderlayout 
Java :: java coding standards for classes 
Java :: Vowel or consonant in java using if else 
Java :: 1.13. programacion orientada a objetos en java 
Java :: local inner class in java 
Java :: jgit clone in memory 
Java :: java.lang.NoClassDefFoundError: net/sf/cb2xml/def/IItem 
Sql :: mysql disable foreign key checks 
Sql :: oracle change nls_date_format permanently 
Sql :: convert utc to est sql 
Sql :: forgot mysql root password stackoverflow 
Sql :: mysql how to reset primary key 
Sql :: get tables in database sql 
Sql :: mysql get date diff in months 
Sql :: query to list all tables in sql database 
Sql :: string to date postgres 
Sql :: flutter sqlite auto incrementing id primary key 
Sql :: oracle search code in packages 
Sql :: get the list of all tables in sql server 
Sql :: mssql show database size 
Sql :: how to remove unique key constraint in mysql 
Sql :: convert int to string in sql server 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =