Created
May 8, 2022 08:14
-
-
Save prasath95/529a862399088126975bee34d3ca1099 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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