Kame3

[LISTA]-Delete_a_given_node_element_1st_occurencce

Aug 24th, 2021 (edited)
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. public static void promeni_lista(SLL<Integer> lista, int x) {
  2.         SLLNode<Integer> d1 = lista.getFirst();
  3.         SLLNode<Integer> prev = null;
  4.  
  5.         if (d1 != null && d1.element == x) {
  6.             d1 = d1.succ;
  7.         }
  8.         while (d1 != null && d1.element != x) {
  9.             prev = d1;
  10.             d1 = d1.succ;
  11.         }
  12.  
  13.         if (d1 == null) {
  14.             return;
  15.         }
  16.  
  17.         prev.succ = d1.succ;
  18.  
  19.         System.out.println(lista.toString());
  20.     }
Add Comment
Please, Sign In to add comment