/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
void reorderList(ListNode* head) {
ListNode *tmp = head;
vector<int> arr_num;
while(tmp!=nullptr)
{
arr_num.push_back(tmp->val);
tmp = tmp -> next;
}
int node_num = arr_num.size()/2;
tmp = head;
ListNode *tmp_next;
while(node_num--)
{
ListNode *new_node = new ListNode(arr_num[arr_num.size() - ( arr_num.size()/2 - node_num)]);
// cout<<new_node->val<<endl;
tmp_next = tmp->next;
tmp->next = new_node;
new_node->next = tmp_next;
if(node_num == 0 && arr_num.size()%2 == 0) new_node->next = nullptr;
else if(node_num == 0 && arr_num.size()%2 == 1) new_node->next->next = nullptr;
else tmp = tmp->next->next;
}
}
};