# Can anyone provide a solution without using the dummy node?

• This solution is not appropriate if the information in each node is huge. Is there any way of doing this without the dummy node?

• ``````/**
* public class ListNode {
*     public int val;
*     public ListNode next;
*     public ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode Partition(ListNode head, int x) {
ListNode left = null;
ListNode rightTail = null;

{
{
if (left == null)
{
left.next = null;
result = left;
}
else
{
left = left.next;
left.next = null;
}
}
else
{
{
rightTail.next = null;
} else
{
rightTail = rightTail.next;
rightTail.next = null;
}
}
}
if (left == null) return rightHead;
return result;
}
}``````

• ``````ListNode* partition(ListNode* head, int x) {

if(pSmall==NULL){
}
else{
}
}
else{
if(pBig==NULL){
}
else{
}
}
}

}``````

• class Solution
{
public:

``````ListNode * partition(ListNode * head, int x)
{
{
return NULL;
}

while (pstTail -> next != NULL)
{
pstTail = pstTail -> next;
}

{
}

ListNode * pstWorkerTail = pstTail;

while (pstWorkerCurr != pstWorkerTail)
{
if (pstWorkerCurr -> val < x)
{
pstWorkerCurr = pstWorkerCurr -> next;
}
else
{
ListNode * pstDelete = pstWorkerCurr -> next;
swap(pstWorkerCurr, pstDelete);

if (pstDelete != pstTail)
{
pstWorkerCurr -> next = pstDelete -> next;
pstDelete     -> next = NULL;
pstTail       -> next = pstDelete;
pstTail               = pstDelete;
}

if (pstDelete == pstWorkerTail)
{
break;
}
}
}

if (pstWorkerCurr -> val >= x)
{
ListNode * pstDelete = pstWorkerCurr -> next;

if (pstDelete != NULL)
{
swap(pstWorkerCurr, pstDelete);

if (pstDelete != pstTail)
{
pstWorkerCurr -> next = pstDelete -> next;
pstDelete     -> next = NULL;
pstTail       -> next = pstDelete;
pstTail               = pstDelete;
}
}
}

}
``````

private:

``````void swap(ListNode * pstNode1, ListNode * pstNode2)
{
int iSwapValue  = pstNode1 -> val;
pstNode1 -> val = pstNode2 -> val;
pstNode2 -> val = iSwapValue;
}
``````

};

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.