Overview of Stack Data Structure π€π
class Stack: def __init__(self): self.items = [] def isEmpty(self) -> bool: return self.items == [] def push(self, data: any) -> list: self.items.append(data) def pop(self) -> any: return self.items.pop() def peek(self) -> any: return self.items[len(self.items) - 1] def size(self) -> int: return len(self.items) s = Stack() #Add element to Stack s.push(1) s.push(2) s.push("hello") #size of stack n = s.size() print("Stack Size {}".format(n)) #delete element print(s.pop()) #pick top element print(s.peek()) #check empty print(s.isEmpty())
Recommended Reading: Balanced Parentheses Check in Python π
If you like my post please follow me to read my latest post on programming and technology.
Build an autocomplete system that, given a query string s and a set of possible…
Design a job scheduler that accepts a function f and an integer n. The scheduler…
Problem Statement (Asked By Airbnb) Given a list of integers, write a function to compute…
A unival tree (short for "universal value tree") is a tree in which all nodes…
Problem Statement (Asked By Facebook) Given the mapping a = 1, b = 2, ...,…
An XOR-linked list is a memory-efficient version of a doubly linked list. Instead of each…