Advertisement
ariestamirra

tambah sebelum

Nov 20th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public static <T> Node tambahNode_Sebelum(Node<T> front, Node<T> newNode, Node<T> target) {
  2.         Node<T> temp = front;
  3.         Node<T> temp1 = null;
  4.  
  5.         while (temp != null) {
  6.             if (temp.nodeValue.equals(target.nodeValue)) {
  7.                 if (temp1 == null) {
  8.                     newNode.next = front;
  9.                     front = newNode;
  10.                 } else {
  11.                     temp1.next = newNode;
  12.                     newNode.next = temp;
  13.                 }
  14.                 return front;
  15.             }
  16.  
  17.             temp1 = temp;
  18.             temp = temp.next;
  19.         }
  20.         return front;
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement