Let us initialize first and last nodes of three linked lists 1 ) Linked list of values smaller than x . 2 ) Linked list of values equal to x . 3 ) Linked list of values greater than x .
Node smallerHead = null , smallerLast = null ; Node greaterLast = null , greaterHead = null ; Node equalHead = null , equalLast = null ;