@@ -331,12 +331,6 @@ public Trie get(char c) {
331
331
*/
332
332
public static Node deleteAllEvenPositionNodes (Node head ) {
333
333
int len = length (head );
334
-
335
- if (head == null ) {
336
- System .out .printf ("\n List is empty\n " );
337
- return null ;
338
- }
339
-
340
334
// if list have single node
341
335
// then return
342
336
if (len < 2 ) {
@@ -362,16 +356,13 @@ public static void deleteAllOddPositionNodes(Node head) {
362
356
return ;
363
357
}
364
358
Node current = head ;
365
- while ( true ) {
359
+ do {
366
360
Node toBeDeleted = current .next ;
367
361
// Note: current.next.next can not be null in circular list.
368
362
current .next = current .next .next ;
369
363
toBeDeleted .next = null ;
370
364
current = current .next ;
371
- if (current == head || current .next == head ) {
372
- break ;
373
- }
374
- }
365
+ } while (current != head && current .next != head );
375
366
}
376
367
377
368
// Function to delete first. returns new head
@@ -419,10 +410,6 @@ private static int length(Node head) {
419
410
public static class Node {
420
411
Node next ;
421
412
int val ;
422
-
423
- String toShortString () {
424
- return String .format ("{%d}" , val );
425
- }
426
413
}
427
414
428
415
// ========================== End of Task 4.1 ========================================
@@ -671,20 +658,6 @@ public static class GiveCountMessage {
671
658
int count ;
672
659
}
673
660
674
- /**
675
- * Simple message
676
- * - senderId to not send message back
677
- * - bunkerIdToCount have set of ids to send across.
678
- * - isLasMessage to send final message from neighbours.
679
- */
680
- public class Message {
681
- int senderId ;
682
- // how to send to next
683
- int ttl ;
684
- Map <Integer , Integer > bunkerIdToCount ;
685
- boolean isLastMessage ;
686
- }
687
-
688
661
// ========================== End of Task 4.2 ========================================
689
662
690
663
0 commit comments