Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int deleteAllNodesWithEvenValues()
- {
- // Delete all the nodes in the list containing even values, returning how many were deleted.
- ListNode current = head;
- int counter = 0;
- current = current.next;
- while(current.next != head){
- if(current.data % 2 == 0){
- ListNode temp = current.next;
- current.next = temp.next;
- counter++;
- }else{
- current = current.next;
- }
- }
- return counter-1;
- }
Add Comment
Please, Sign In to add comment