Advertisement
sajid161

12:2

Jan 9th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. queue<int> modifyQueue(queue<int> q, int k)
  2. {
  3.    stack<int> st;
  4.    queue<int> q1;
  5.    int coun=0;
  6.    while(!q.empty())
  7.    {    if(coun==k) break;
  8.        st.push(q.front());
  9.        q.pop();
  10.        coun++;
  11.    }
  12.    while(!st.empty())
  13.    {
  14.       q1.push(st.top());
  15.       st.pop();
  16.    }
  17.     while(!q.empty())
  18.    {
  19.       q1.push(q.front());
  20.       q.pop();
  21.    }
  22.    return q1;
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement