impl: custom linked list
This commit is contained in:
@@ -27,6 +27,21 @@ public class CustomLinkedListImpl<T> implements CustomLinkedList<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CustomLinkedListNode<T> traverseFind(CustomLinkedListNode<T> currentNode, T item) {
|
||||||
|
|
||||||
|
CustomLinkedListNode<T> nextNode = currentNode.getNext();
|
||||||
|
|
||||||
|
if (nextNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentNode.getItem().equals(item)) {
|
||||||
|
return currentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return traverseFind(nextNode, item);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(T item) {
|
public void remove(T item) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
@@ -59,8 +74,7 @@ public class CustomLinkedListImpl<T> implements CustomLinkedList<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(T item) {
|
public boolean contains(T item) {
|
||||||
// TODO Auto-generated method stub
|
return traverseFind(head, item) != null ? true : false;
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'contains'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int recursiveSizeCalc(CustomLinkedListNode<T> node, int count) {
|
private int recursiveSizeCalc(CustomLinkedListNode<T> node, int count) {
|
||||||
|
|||||||
Reference in New Issue
Block a user