Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Initial Template for C++
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- queue<ll> modifyQueue(queue<ll> q, int k);
- int main(){
- ll t;
- cin>>t;
- while(t-->0){
- ll n,k;
- cin>>n>>k;
- queue<ll> q;
- while(n-->0){
- ll a;
- cin>>a;
- q.push(a);
- }
- queue<ll> ans=modifyQueue(q,k);
- while(!ans.empty()){
- int a=ans.front();
- ans.pop();
- cout<<a<<" ";
- }
- cout<<endl;
- }
- }// } Driver Code Ends
- //User function Template for C++
- queue<ll> modifyQueue(queue<ll> q, int k)
- {
- stack<int>s;
- queue<int>p;
- while(k--)
- {
- s.push(q.front());
- q.pop();
- }
- while(!q.empty()){
- p.push(q.front());
- q.pop();
- }
- while(!s.empty()){
- q.push(s.top());
- s.pop();
- }
- while(!p.empty()){
- q.push(p.front());
- p.pop();
- }
- return q;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement