stack.py
1.0.0
stack.py เป็นการใช้งาน LIFO Stack & Fifo Queue ใน Python มันไม่ได้เป็นชนิดข้อมูลที่แตกต่างกัน แต่สามารถถือว่าเป็นหนึ่ง
LIFO - สุดท้ายเข้ามาก่อน องค์ประกอบสุดท้ายที่จะเข้ามาจะเป็นคนแรกที่ออกไป
FIFO - ครั้งแรกในครั้งแรก องค์ประกอบแรกที่จะเข้ามาจะเป็นคนแรกที่ออกไป
จัดทำโดย: shields.io
วิธีที่ง่ายที่สุดคือการติดตั้ง stack.py ด้วย pip
pip install stack.py from stack import Stack
s = Stack ( 6 ) # Create a LIFO stack with stack length 6
s . put ( 1 ) # Pushing some elements to the stack
s . put ( 2 )
s . put ( 3 )
s . get () # Gets an element from the stack, pops it
s . list # Returns the elements of stack as a list
s . top # Returns the index of top pointer of the stack
s . list [ s . top ] # Returns the value of the element at top
s . empty # Returns True if the stack is empty else returns False
s . clear () # Clears the stack, and makes it empty
p = s . copy () # Creates a copy of stack as an independent object
print ( s ) # Prints the element of stacks as a stringified list
print ( repr ( s )) # Returns the class object representation of the stack with the values it holds from stack import Queue
q = Queue ( 10 ) # Create a FIFO queue with queue length 6
q . enqueue ( 1 ) # Enqueues elements to the queue
q . enqueue ( 2 )
q . enqueue ( 3 )
q . dequeue () # Gets an element from the queue, pops it
q . list # Returns the elements of queue as a list
q . front # Returns the index of front pointer of the stack
q . rear # Returns the index of rear pointer of the stack
q . list [ s . rear ] # Returns the value of the rear element
q . empty # Returns True if the queue is empty else returns False
q . clear () # Clears the queue, and makes it empty
t = q . copy () # Creates a copy of stack as an independent object
print ( q ) # Prints the element of queue as a stringified list
print ( repr ( q )) # Returns the class object representation of the queue with the values it holds ยินดีต้อนรับการมีส่วนร่วมเสมอ!
โปรดปฏิบัติตาม code of conduct ของ GitHub
ใบอนุญาต Apache 2.0