Wednesday 17 October 2012

convert queue into stack and make list work as queue and stack both

now we will see how one can convert QUEUE into STACK into python -- !


from collections import deque

list =[1,2,3,4,5]

queue_list = deque(list)

now queue_list will work as a queue object .... :)
---------------------------------------------------------------
you can extract any element from queue_list by using--

queue_list.popleft()
----------------------------------------this all thing is working as a queue object
now we just need to use a simple method pop() to work queue_list as a stack
-------------------------------------------------------------------------------------------------
queue_list.pop()
u can use also queue_list.popleft()  to work this list as a queue.


Thank You
Meet Me
Prashant Gaur


No comments:

Post a Comment