<p>You are given the head of a singly linked-list. The list can be represented as:</p>

<pre>
L<sub>0</sub> &rarr; L<sub>1</sub> &rarr; &hellip; &rarr; L<sub>n - 1</sub> &rarr; L<sub>n</sub>
</pre>

<p><em>Reorder the list to be on the following form:</em></p>

<pre>
L<sub>0</sub> &rarr; L<sub>n</sub> &rarr; L<sub>1</sub> &rarr; L<sub>n - 1</sub> &rarr; L<sub>2</sub> &rarr; L<sub>n - 2</sub> &rarr; &hellip;
</pre>

<p>You may not modify the values in the list&#39;s nodes. Only nodes themselves may be changed.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/04/reorder1linked-list.jpg" style="width: 422px; height: 222px;" />
<pre>
<strong>Input:</strong> head = [1,2,3,4]
<strong>Output:</strong> [1,4,2,3]
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/reorder2-linked-list.jpg" style="width: 542px; height: 222px;" />
<pre>
<strong>Input:</strong> head = [1,2,3,4,5]
<strong>Output:</strong> [1,5,2,4,3]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the list is in the range <code>[1, 5 * 10<sup>4</sup>]</code>.</li>
	<li><code>1 &lt;= Node.val &lt;= 1000</code></li>
</ul>



/*

MY FIRST INTUTION
here i didnot read the question properly and tried to change value insted of nodes

*/
class Solution {
public:
    
    void getorder(ListNode* head,vector<int>& v)
    {
        while(head!=NULL)
        {
            v.push_back(head->val);
            head=head->next;
        }
    }
    
    
    void display(ListNode* head)
    {
         while(head!=NULL)
        {
            cout<<head->val<<" ";
            head=head->next;
        }
        
        cout<<endl;
    }
    
    
    
    
    void reorderList(ListNode*& head) {
        
        vector<int> v;
        getorder(head,v);
        
        
        int i=0;
        int j = v.size()-1;
        ListNode* current = new ListNode(-1);
        ListNode* c = NULL;
        
        current->next=c;
        
        while(j>i)
        {
            //cout<<"i entered here for i and j "<<i<<" "<<j<<endl;
            
            ListNode* a = new ListNode(v[i]);
            ListNode* b = new ListNode(v[j]);
            
            a->next=b;
            
            if(c==NULL)
            {
                //cout<<"i entered here\n";
                current=a;
                c=b;
                
            }else{
                
                //cout<<"mai aab yaha aaya\n";
                c->next=a;
                c=b;
            }
            
            i++;
            j--;
            
           
            
            
        }
        
            if(i==j)
            {
                //cout<<"idher aana nahi pada\n";
                 ListNode* a = new ListNode(v[j]);
                if(c==NULL)
                {
                    current=a;
                }else{
                    c->next=a;
                }
                
            }
        
       
         head->next=current->next;
         //head=head->next;
         //current;
        
         
        // ListNode* p =cuuernt;
        
        //display(head);
        
        
        
    }
};



25300