title: copying Queue and Stack into each other
body: <p>I want to use an empty stack S to check whether a Queue Q contaitns element x, thus my solution was to copy elements of Q into S and check if contain x, but I'm also asked to return S elements into Q again as it was originaly, this must be done using only a Q and S without any other arrays of SL, so I have written this algorithm:</p>
  
  <pre><code>Boolean found ← false
  int element ←  0
  While(Q is not empty) 
  
    element ← Q.dequeue()
    if(element equal x)
             found ← true
    S.push(element)
  
  While(S is not empty)
   ( elements back to Q) ?
  </code></pre>
  
  <p>stuck in last step, if I used Q.enqueue(S.pop) then the order of elements in Q will be reversed</p>