Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lesson 9
# Object Oriented Programming - Data Structure Stack ''' Stack - LIFO (Last In First Out) 1. Extracting book 4 Book 1 --->> Book 2 --->> Book 3 --->> Book 4 Book 4 Book 5 Book 5 Book 6 Book 6 2. Removing from pile of books (always the thing on top) (Popping) Book 4 --->> Book 3 Book 2 Book 1 3. Adding Book 5 to the pile (always on the top) (Pushing) Book 5 Book 4 Book 3 Book 2 Book 1 ''' class Stack: def __init__(self): self.items = [] # empty list def push(self, add_an_item): return self.items.append(add_an_item) def pop(self): if self.isEmpty() is True: return [] else: # stack not empty return self.items.pop() def show(self): print (self.items[:]) def isEmpty(self): if self.items == []: return True else: return False def size(self): return len(self.items) stack_1 = Stack() stack_1.push('Pillow') stack_1.push('Brush') stack_1.push('Mattress') stack_1.push('Bags') stack_1.push('Car') stack_1.pop() stack_1.push('Pillow') stack_1.push('Brush') stack_1.push('Mattress') stack_1.push('Bags') stack_1.push('Car') print (stack_1.size()) stack_1.pop() stack_1.pop() stack_1.show()
run
|
edit
|
history
|
help
0
shuru16
abc python basic
Magic Calendar of any month
sheru1
9th jan1
Algorytm szybkiego potęgowania
Regular falsi
shuru3
2.1.19
PyRegBackRef