Untitled

mail@pastecode.io avatar
unknown
plain_text
10 months ago
453 B
1
Indexable
Never
#include <bits/stdc++.h> 
void interLeaveQueue(queue < int > & q) {

    queue<int>q2;
    int n=q.size();

    for(int i=0;i<n/2;i++){ //taking 1st half of q into q2
        int f=q.front();
        q.pop();
        q2.push(f);
    }
    while(!q2.empty()){        //intermittently adding q and q2
        int f1=q2.front();
        q2.pop();
        q.push(f1);
        int f2=q.front();
        q.pop();
        q.push(f2);
    }
}