C++ using pointer to pointer


#1
ListNode* Solution::partition(ListNode* A, int B) {
    auto dummy_bigger_obj = ListNode(0);
    auto dummy_smaller_obj = ListNode(0);
    
    ListNode *bigger_dummy, *bigger_node, *smaller_dummy, *smaller_node;
    bigger_dummy = bigger_node = &dummy_bigger_obj;
    smaller_dummy= smaller_node = &dummy_smaller_obj;
    
    auto node = A;
    
    while (node) {
        ListNode** p2_dst = (node->val < B)? &smaller_node : &bigger_node;
        
        (*p2_dst)->next = node;
        node = node->next;
        
        (*p2_dst)->next->next = nullptr;
        (*p2_dst)=(*p2_dst)->next;
    }
    
    smaller_node->next = bigger_dummy->next;
    
    return smaller_dummy->next;
}