Java code for linked list |
|
Public Class Node{ Public Node nextNode; Public String data; }
Public LinkedList { Private Node start = null; Public addString(String data){ Node temp = new Node(); Node currentNode = start; Temp.nextNode = null; Temp.data = data; // if no elements have been added, add the first one If (currentNode == null) { Start = temp; } Else{ // find the end of the list While(currentNode.nextNode != null){ currentNode = currentNode.nextNode; }
currecntNode.nextNode = temp; } }
// a return of null means it was not found Public Node findNode(String data){ If (start == null) return null; Node currentNode = start; Repeat{ If (currentNode.data = data) return currentNode; currentNode = currentNode.nextNode; }Until (currentNode == null) } } |