Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean delElementByValue(E value) {
- Node<E> resultNode = firstNode;
- while (resultNode != null) {
- //NullPointerException в следующей строке
- if (resultNode.getNodeValue().equals(value)) {
- resultNode.getPrevNode().setNextNode(resultNode.getNextNode());
- return true;
- }
- resultNode = resultNode.getNextNode();
- }
- return false;
- }
- class Node<E> {
- private Node<E> prevNode;
- private Node<E> nextNode;
- private E nodeValue;
- Node(Node<E> prevNode, Node<E> nextNode, E nodeValue) {
- this.prevNode = prevNode;
- this.nextNode = nextNode;
- this.nodeValue = nodeValue;
- }
- public void setNodeValue(E nodeValue) {
- this.nodeValue = nodeValue;
- }
- public void setPrevNode(Node<E> prevNode) {
- this.prevNode = prevNode;
- }
- public void setNextNode(Node<E> nextNode) {
- this.nextNode = nextNode;
- }
- public Node<E> getPrevNode() {
- return prevNode;
- }
- public Node<E> getNextNode() {
- return nextNode;
- }
- public E getNodeValue() {
- return nodeValue;
- }
- }
Add Comment
Please, Sign In to add comment