java - copying Queue and Stack into each other -


i want use empty stack s check whether queue q contaitns element x, solution copy elements of q s , check if contain x, i'm asked return s elements q again originaly, must done using q , s without other arrays of sl, have written algorithm:

boolean found ← false int element ←  0 while(q not empty)     element ← q.dequeue()   if(element equal x)            found ← true   s.push(element)  while(s not empty)  ( elements q) ? 

stuck in last step, if used q.enqueue(s.pop) order of elements in q reversed

correct, order reversed. means if repeat algorithm yet again (all s , q) reverse yet again, meaning original order of elements, want.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -