1
0

LIFOQueue.py 852 B

123456789101112131415161718192021222324252627
  1. # The contents of this file are subject to the Python Software Foundation
  2. # License Version 2.3 (the License). You may not copy or use this file, in
  3. # either source code or executable form, except in compliance with the License.
  4. # You may obtain a copy of the License at http://www.python.org/license.
  5. #
  6. # Software distributed under the License is distributed on an AS IS basis,
  7. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. # for the specific language governing rights and limitations under the
  9. # License.
  10. #
  11. # by Greg Hazel
  12. from Queue import Queue
  13. class LIFOQueue(Queue):
  14. # Get an item from the queue
  15. def _get(self):
  16. return self.queue.pop()
  17. if __name__ == '__main__':
  18. l = LIFOQueue()
  19. for i in xrange(10):
  20. l.put(i)
  21. j = 9
  22. for i in xrange(10):
  23. assert l.get() == j - i