(int n)
| 150 | } |
| 151 | |
| 152 | public void removeNthfromEnd(int n) { |
| 153 | //size |
| 154 | int size = 0; |
| 155 | Node temp = head; |
| 156 | while(temp != null) { |
| 157 | temp = temp.next; |
| 158 | size++; |
| 159 | } |
| 160 | //if we have to remove the head |
| 161 | if(n == size) { |
| 162 | head = head.next; |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | int i = 1; |
| 167 | int itf = size-n; |
| 168 | Node prev = head; |
| 169 | while(i < itf) { //try to find the node previous of nth |
| 170 | prev = prev.next; |
| 171 | i++; |
| 172 | } |
| 173 | prev.next = prev.next.next; |
| 174 | } |
| 175 | |
| 176 | private Node findMidNode(Node head) { |
| 177 | Node slow = head; |
nothing calls this directly
no outgoing calls
no test coverage detected