File tree 2 files changed +20
-20
lines changed
src/main/java/com/rampatra/linkedlists
2 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ public static <E extends Comparable<E>> boolean isLoopPresentUsingHashMap(Single
55
55
HashMap <SingleLinkedNode <E >, Boolean > map = new HashMap <>();
56
56
SingleLinkedNode <E > curr = node ;
57
57
while (curr != null ) {
58
- if (map .get (curr ) != null && map .get (curr ) == true ) {
58
+ if (map .get (curr ) != null && map .get (curr )) {
59
59
return true ;
60
60
}
61
61
map .put (curr , true );
@@ -66,12 +66,12 @@ public static <E extends Comparable<E>> boolean isLoopPresentUsingHashMap(Single
66
66
67
67
public static void main (String a []) {
68
68
SingleLinkedList <Integer > linkedList = new SingleLinkedList <>();
69
- linkedList .add (00 );
70
- linkedList .add (11 );
71
- linkedList .add (22 );
72
- linkedList .add (33 );
73
- linkedList .add (44 );
74
- linkedList .add (55 );
69
+ linkedList .add (0 );
70
+ linkedList .add (1 );
71
+ linkedList .add (2 );
72
+ linkedList .add (3 );
73
+ linkedList .add (4 );
74
+ linkedList .add (5 );
75
75
linkedList .getNode (4 ).next = linkedList .getNode (3 );
76
76
System .out .println (isLoopPresent (linkedList ));
77
77
}
Original file line number Diff line number Diff line change @@ -43,26 +43,26 @@ public static <E extends Comparable<E>> SingleLinkedNode<E> reverseLinkedListInG
43
43
44
44
// recursively call for the rest of the nodes in the linked list
45
45
if (next != null ) {
46
- node .next = reverseLinkedListInGroups (next , k );
46
+ node .next = reverseLinkedListInGroups (curr , k );
47
47
}
48
48
49
49
return prev ;
50
50
}
51
51
52
52
public static void main (String a []) {
53
53
SingleLinkedList <Integer > linkedList = new SingleLinkedList <>();
54
- linkedList .add (00 );
55
- linkedList .add (11 );
56
- linkedList .add (22 );
57
- linkedList .add (33 );
58
- linkedList .add (44 );
59
- linkedList .add (55 );
60
- linkedList .add (66 );
61
- linkedList .add (77 );
62
- linkedList .add (88 );
63
- linkedList .add (99 );
64
- linkedList .add (100 );
54
+ linkedList .add (0 );
55
+ linkedList .add (1 );
56
+ linkedList .add (2 );
57
+ linkedList .add (3 );
58
+ linkedList .add (4 );
59
+ linkedList .add (5 );
60
+ linkedList .add (6 );
61
+ linkedList .add (7 );
62
+ linkedList .add (8 );
63
+ linkedList .add (9 );
64
+ linkedList .add (10 );
65
65
linkedList .printList ();
66
- linkedList .printList (reverseLinkedListInGroups (linkedList .head , 3 ));
66
+ SingleLinkedList .printList (reverseLinkedListInGroups (linkedList .head , 3 ));
67
67
}
68
68
}
You can’t perform that action at this time.
0 commit comments