dzonbrodaty

Untitled

Mar 19th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. public int deleteAllNodesWithEvenValues()
  2. {
  3. // Delete all the nodes in the list containing even values, returning how many were deleted.
  4. ListNode current = head;
  5. int counter = 0;
  6. current = current.next;
  7.  
  8. while(current.next != head){
  9. if(current.data % 2 == 0){
  10. ListNode temp = current.next;
  11. current.next = temp.next;
  12. counter++;
  13. }else{
  14. current = current.next;
  15.  
  16. }
  17. }
  18.  
  19.  
  20. return counter-1;
  21. }
Add Comment
Please, Sign In to add comment