diff --git a/Queue using.py b/Queue using.py new file mode 100644 index 00000000..93f717ec --- /dev/null +++ b/Queue using.py @@ -0,0 +1,27 @@ +def __init__(self): + self.s1 = [] + self.s2 = [] + + +def push(self, x: int) -> None: + self.s1.append(x) + + + +def pop(self) -> int: + if not self.s2: + while self.s1: + self.s2.append(self.s1.pop()) + return self.s2.pop() + +def peek(self) -> int: + if not self.s2: + while self.s1: + self.s2.append(self.s1.pop()) + return self.s2[-1] + + + +def empty(self) -> bool: + return not self.s1 and not self.s2 + \ No newline at end of file