Question | Answer |
Delete all occurrences of a key in a linked list | public void deleteKey(ListNode head, int key){ ListNode temp = head; ListNode = prev; while(temp != null && temp.data ==key){ head = temp.next; temp= head; } while(temp!=null){ while(temp!=null && temp.data!=key){ prev = temp; temp= temp.next; } if(temp == null) return; prev.next = temp.next; temp = prev.next; } } |
There are no comments, be the first and leave one below:
Want to create your own Flashcards for free with GoConqr? Learn more.