Skip to content

Instantly share code, notes, and snippets.

@devsingh1234
Created February 18, 2022 18:03
Show Gist options
  • Save devsingh1234/2feb5fa015d485eb6028e7b4088df18c to your computer and use it in GitHub Desktop.
Save devsingh1234/2feb5fa015d485eb6028e7b4088df18c to your computer and use it in GitHub Desktop.
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