File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
src/me/ramswaroop/linkedlists Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change 13
13
public class DivideCircularListIntoTwo <E extends Comparable <E >> extends CircularSingleLinkedList <E > {
14
14
15
15
public static <E extends Comparable <E >> CircularSingleLinkedList [] divideIntoTwoHalves (CircularSingleLinkedList <E > list ) {
16
- SingleLinkedNode <E > middleNode = list .getNode (list .size >> 1 ),
16
+ SingleLinkedNode <E > middleNode = list .getNode (list .size - 1 >> 1 ),
17
17
lastNode = list .getNode (list .size - 1 ),
18
18
secondHead = middleNode .next ;
19
-
19
+ // make the 2nd half circular first
20
20
lastNode .next = middleNode .next ;
21
+ // then make the 1st half circular
21
22
middleNode .next = list .head ;
22
23
23
24
return new CircularSingleLinkedList []{getLinkedList (list .head ), getLinkedList (secondHead )};
You can’t perform that action at this time.
0 commit comments