Check out example codes for "how to add to the end of a linked list". It will help you in understanding the concepts better.

Code Example 1

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 (( != null)) {
           header =;

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

Code Example 2

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 *append(node *head, int val){
    node *tmp = head;
    node *createdNode = createNode(val);

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

    tmp->next = createdNode;
    return head;

Learn ReactJs, React Native from