Python Stack

stack = []
stack.append(10)
stack.append(12)
stack.append(15)
print("After Data Insertion (PUSH)")
for i in range(len(stack)):
    print(stack[i])

stack.pop()
print("After deletion Data (POP): ")
for i in range(len(stack)):
    print(stack[i])

আমরা ক্লাস ব্যবহার করে ও stack অপারেশান দেখতে পারি।

 

class Stack:

    def __init__(self):
        self.stack = []

    def addItem(self, data):

            self.stack.append(data)
            return True
      
    def peek(self):  
           
      return self.stack[len(ob1.stack)-1]

ob1 = Stack()
ob1.addItem(10)
ob1.addItem(12)
ob1.addItem(15)

print("Appended data are: data are:")
for i in range(len(ob1.stack)):
    print( ob1.stack[i])

ob1.peek()
print("Last inserted Data:", ob1.peek())

Leave a Reply

Your email address will not be published. Required fields are marked *