Guest User

Untitled

a guest
Apr 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public boolean delElementByValue(E value) {
  2. Node<E> resultNode = firstNode;
  3. while (resultNode != null) {
  4. //NullPointerException в следующей строке
  5. if (resultNode.getNodeValue().equals(value)) {
  6. resultNode.getPrevNode().setNextNode(resultNode.getNextNode());
  7. return true;
  8. }
  9. resultNode = resultNode.getNextNode();
  10. }
  11. return false;
  12. }
  13.  
  14. class Node<E> {
  15. private Node<E> prevNode;
  16. private Node<E> nextNode;
  17. private E nodeValue;
  18.  
  19. Node(Node<E> prevNode, Node<E> nextNode, E nodeValue) {
  20. this.prevNode = prevNode;
  21. this.nextNode = nextNode;
  22. this.nodeValue = nodeValue;
  23. }
  24.  
  25. public void setNodeValue(E nodeValue) {
  26. this.nodeValue = nodeValue;
  27. }
  28.  
  29. public void setPrevNode(Node<E> prevNode) {
  30. this.prevNode = prevNode;
  31. }
  32.  
  33. public void setNextNode(Node<E> nextNode) {
  34. this.nextNode = nextNode;
  35. }
  36.  
  37. public Node<E> getPrevNode() {
  38. return prevNode;
  39. }
  40.  
  41. public Node<E> getNextNode() {
  42. return nextNode;
  43. }
  44.  
  45. public E getNodeValue() {
  46. return nodeValue;
  47. }
  48. }
Add Comment
Please, Sign In to add comment