DEV Community

Cover image for Data Structure in Python3: Stack
luthfisauqi17
luthfisauqi17

Posted on

Data Structure in Python3: Stack

class Stack:
    def __init__(self):
        self.arr = []

    def pop(self):
        data = self.arr.pop()
        return data

    def push(self, data):
        self.arr.append(data)

    def peek(self):
        return self.arr[len(self.arr)-1]

    def isEmpty(self):
        return len(self.arr) == 0
Enter fullscreen mode Exit fullscreen mode

Sources and Images:

Discussion (0)