Saturday 10 February 2018

create a link list in java and link all the node to each other

create a link list in java and link all the node to each other,create a link list in java ,

Create a link list in java:-

In this tutorial we are going to create LinkedList using java and link all the node to each other but in this code it will not print anything..

package com.dashzin.linklist;

public class LinkList {
     Node head;// head of list

    /* Linked list Node...And This inner class is made static so that
       main() can access it */
     static class Node{
          int data;
          Node next;
         
          Node(int data){
              this.data=data;
              next=null;
          }
     }

     public static void main(String args[]){
    
          // creating four node for linklist
          LinkList lkl=new LinkList();
          lkl.head=new Node(1);
         
          Node first=new Node(2);
          Node sec=new Node(3);
          Node third=new Node(4);
         
          //Link all the node with each other.....
         
          lkl.head.next=first;
          first.next=sec;
          sec.next=third;
     }
}

 If you are not getting how it has done then please just see the previous post of this topic... 






DashZin

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comments:

Post a Comment