Leetcode Reorder List problem solution

In this Leetcode Reorder List problem solution, we have given the head of a singly linked list. The list can be represented as:

L0 → L1 → … → Ln - 1 → Ln

Reorder the list to be on the following form:

L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …

You may not modify the values in the list's nodes. Only nodes themselves may be changed.

Problem solution in Python.

```class Solution(object):
q = []
p = dummy = ListNode(0)

while len(q)>1:
h = q.pop(0)
t = q.pop()
p.next = h
h.next = t
p = t
p.next = None

if q:
p.next = q.pop()
p = p.next
p.next = None

return dummy.next
```

Problem solution in Java.

```public void reorderList(ListNode head) {

while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}

if (slow != null) {
ListNode next = null;
ListNode prev = null;
ListNode current = slow.next;

while (current != null) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}

slow.next = null;
}

}
}
}
```

Problem solution in C++.

```class Solution {
public:
{
return a;
}

{
return;
return;
while(fast!=NULL && fast->next!=NULL)
{
fast=fast->next->next;
slow=slow->next;
}
ListNode* rev =reverse(slow->next);
slow->next=NULL;
ListNode* t2=NULL;
while(temp && rev)
{
ListNode* t1=temp->next;
temp->next=rev;
t2=rev;
temp=t1;
rev=rev->next;
t2->next=t1;
t2=t2->next;
}
if(rev!=NULL)
t2->next=rev;
}
};
```

Problem solution in C.

```struct ListNode* reverseList(struct ListNode *head)
{

while (pCur!=NULL)
{
pNext = pCur->next;
pCur->next = pLast;

pLast = pCur;
pCur = pNext;
}
return pLast;
}

{
int i,len;

for(len=0; pCur; len++, pCur=pCur->next);

for(i=1; i<(len+1)/2 ; i++, pCur=pCur->next);

struct ListNode *pRight = pCur->next;
pCur->next = NULL;
pRight = reverseList(pRight);

struct ListNode *pLeftNext, *pRightNext;
while (pLeft && pRight) {
pLeftNext = pLeft->next;
pRightNext = pRight->next;

pLeft->next = pRight;
pRight->next = pLeftNext;

pLeft = pLeftNext;
pRight = pRightNext;
}