Created
February 18, 2022 18:03
-
-
Save devsingh1234/2feb5fa015d485eb6028e7b4088df18c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LINkedListst; | |
public class LinkedList { | |
private class Node{ | |
int data; | |
Node next; | |
} | |
private Node head; | |
private Node tail; | |
private int size; | |
public void display(){ | |
System.out.println( " ========================== "); | |
Node temp = this.head; | |
while (temp != null){ | |
System.out.print(temp.data + " , "); | |
temp=temp.next; | |
} | |
System.out.println(); | |
System.out.println("======================="); | |
} | |
public void addLast(int item){ | |
//create a new node | |
Node nn = new Node(); | |
nn.data = item; | |
nn.next = null; | |
//attach | |
if(this.size >= 1){ | |
this.tail.next = nn; | |
} | |
//object summary | |
if (this.size == 0){ | |
this.head = nn; | |
this.tail = nn; | |
this.size++; | |
}else { | |
this.tail =nn; | |
this.size++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment