Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2f71ec1

Browse files
author
Ram swaroop
committed
minor fix
1 parent ddecef4 commit 2f71ec1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/me/ramswaroop/linkedlists/DivideCircularListIntoTwo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
public class DivideCircularListIntoTwo<E extends Comparable<E>> extends CircularSingleLinkedList<E> {
1414

1515
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),
1717
lastNode = list.getNode(list.size - 1),
1818
secondHead = middleNode.next;
19-
19+
// make the 2nd half circular first
2020
lastNode.next = middleNode.next;
21+
// then make the 1st half circular
2122
middleNode.next = list.head;
2223

2324
return new CircularSingleLinkedList[]{getLinkedList(list.head), getLinkedList(secondHead)};

0 commit comments

Comments
 (0)