Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to implement linked list in java without using collection framework

public class linkedlist
{
    public static class Node         //We are defining a node  here
    {
        int data;       //data of node here
        Node next;      //next refers to the address of the next node
        
    }
    public static void main(String args[])
    {
        Node newnode1=new Node();    //here we are making objects of class Node
        Node newnode2=new Node();    //basically these are nodes of first linkedlist
        Node newnode3=new Node();    
        Node newnode4=new Node();    
        newnode1.data=1;
        newnode2.data=2;
        newnode3.data=3;
        newnode4.data=4;
         
          
        newnode1.next=newnode2;       //here we are linking the previous node to the next node of the list 
        newnode2.next=newnode3;
        newnode3.next=newnode4;
        newnode4.next=null;

        //Now we will print the linked list

       for (int i=1;i<=4;i++)
        {
            System.out.print(newnode1.data+" ");
            newnode1=newnode1.next;       //we are assigning the next address of the linked list to the current address 
        }
    }
}

<div class="open_grepper_editor" title="Edit & Save To Grepper"></div>
Comment

PREVIOUS NEXT
Code Example
Java :: reading in lines from a file java 
Java :: java string to long 
Java :: java double to string with comma 
Java :: bukkit runnable repeating scheduler 
Java :: java get monitor size 
Java :: javafx listview get item index 
Java :: java remove first digit from int 
Java :: java split string into list 
Java :: centos install openjdk 11 
Java :: how to send file in request body rest assured 
Java :: Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt 
Java :: how to echo java_home in windows cmd 
Java :: get value google sheet with app script 
Java :: polar to cartesian java 
Java :: spring security default username 
Java :: complicated average java code 
Java :: spring boot post request response empty body 
Java :: how to write sensor data into file android studio 
Java :: java check if sql table exists 
Java :: plus one 
Java :: right click java 
Java :: scanner in java 
Java :: how to install java 8 on terminal os 
Java :: java swing absolute position 
Java :: java verify string is hexadecimal 
Java :: Date from String java3 
Java :: java int to binary 
Java :: spring mvc get all request parameters 
Java :: java max integer 
Java :: convert class to xml string 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =