-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
There is an alternative to the current reverse x 3 approach that is also in place and O(n). This alternative might be more memory access friendly as it only loops on the array once in forward order.
// rotate left version
let rotate = function ( a , i , j , k ) {
if ( k <= 0 ) return ;
while ( ( i += k ) + k < j ) swapranges( a , i - k , i , a , i ) ;
swapranges( a , i , j , a , i - k ) ;
rotate( a , j - k , j , k - ( j - i ) ) ; // tail recursion
}
Metadata
Metadata
Assignees
Labels
No labels