Alternating split of a given Singly Linked List | Set 1 |  ; points to the last node in ' a ' ; points to the last node in ' b ' ; add at ' a ' tail ; advance the ' a ' tail
function AlternatingSplit ( source , aRef , bRef ) { var aDummy = new Node ( ) ; var aTail = aDummy ; var bDummy = new Node ( ) ; var bTail = bDummy ; var current = source ; aDummy . next = null ; bDummy . next = null ; while ( current != null ) { MoveNode ( ( aTail . next ) , current ) ; aTail = aTail . next ; if ( current != null ) { MoveNode ( ( bTail . next ) , current ) ; bTail = bTail . next ; } } aRef = aDummy . next ; bRef = bDummy . next ; }