Skip to content

Instantly share code, notes, and snippets.

@prasath95
Created May 8, 2022 08:14
Show Gist options
  • Save prasath95/529a862399088126975bee34d3ca1099 to your computer and use it in GitHub Desktop.
Save prasath95/529a862399088126975bee34d3ca1099 to your computer and use it in GitHub Desktop.
public class LinkedList {
Node headNode;
/*
* insert method
* @value - integer
* */
public void insert(int value){
Node newNode=new Node();
newNode.value=value;
if(headNode==null){
headNode=newNode;
}else{
//4.1
Node n=headNode;
//4.2
while (n.nextNode!=null){
//4.3
n=n.nextNode;
}
//4.4
n.nextNode=newNode;
}
}
}
//for understanding i added Node Class below
public class Node {
int value;
Node nextNode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment