Author Dusty Phillips Reviewers


LIFO ( Last In First Out



Download 2,95 Mb.
Pdf ko'rish
bet180/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   175   176   177   178   179   180   181   182   183
Bog'liq
python3-oop

LIFO
(
Last In First Out
) queues are more frequently called 
stacks
. Think of a stack 
of papers where you can only access the top-most paper. You can put another paper 
on top of the stack, making it the new top-most paper, or you can take the top-most 
paper away to reveal the one beneath it.
Traditionally, the operations on stacks are named push and pop, but the Python
queue
module uses the exact same API as for FIFO queues: 
put()
and 
get()

However, in a LIFO queue, these methods operate on the "top" of the stack instead
of at the front and back of a line. This is an excellent example of polymorphism. If you 
look at the 
Queue
source code in the Python standard library, you'll actually see that 
there is a superclass with subclasses for FIFO and LIFO queues that implement the 
few operations (operating on the top of a stack instead of front and back of a 
deque
instance) that are critically different between the two.
Here's an example of the LIFO queue in action:
>>> from queue import LifoQueue
>>> stack = LifoQueue(maxsize=3)
>>> stack.put("one")
>>> stack.put("two")
>>> stack.put("three")
>>> stack.put("four", block=False)
Traceback (most recent call last):
File "", line 1, in
stack.put("four", block=False)
File "/usr/lib64/python3.3/queue.py", line 133, in put
raise Full
queue.Full
>>> stack.get()
'three'
>>> stack.get()
www.it-ebooks.info


Python Data Structures
[
 186 
]
'two'
>>> stack.get()

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   175   176   177   178   179   180   181   182   183




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish