From 8ebf86378aaedfb7afb5a384238d3db68183bbef Mon Sep 17 00:00:00 2001 From: Samarpreet Singh <99521823+XxPython28xX@users.noreply.github.com> Date: Sun, 8 Oct 2023 12:37:05 +0530 Subject: [PATCH 01/12] added stack_using_two_queues.py --- .../stacks/stack_using_two_queues.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 data_structures/stacks/stack_using_two_queues.py diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py new file mode 100644 index 000000000000..c9bd06dadbf9 --- /dev/null +++ b/data_structures/stacks/stack_using_two_queues.py @@ -0,0 +1,50 @@ +class Stack: + def __init__(self): + self.items = [] + + def push(self, item): + self.items.append(item) + + def pop(self): + if not self.is_empty(): + return self.items.pop() + else: + return "Stack is empty" + + def peek(self): + if not self.is_empty(): + return self.items[-1] + else: + return "Stack is empty" + + def is_empty(self): + return len(self.items) == 0 + + def size(self): + return len(self.items) + +# Create a stack +stack = Stack() + +# PUSH operation +stack.push(1) +stack.push(2) +stack.push(3) + +# Display the stack +print("Stack:", stack.items) + +# POP operation +popped_item = stack.pop() +print("Popped item:", popped_item) + +# Display the updated stack +print("Stack after POP:", stack.items) + +# PEEK operation +top_item = stack.peek() +print("Top item (PEEK):", top_item) + +# Check the size of the stack +stack_size = stack.size() +print("Stack size:", stack_size) From 494e92fc9d67ab6cbd1b38754ec64a31b01c7d58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 07:09:04 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/stacks/stack_using_two_queues.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index c9bd06dadbf9..1cab76afb00c 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -4,7 +4,7 @@ def __init__(self): def push(self, item): self.items.append(item) - + def pop(self): if not self.is_empty(): return self.items.pop() @@ -23,6 +23,7 @@ def is_empty(self): def size(self): return len(self.items) + # Create a stack stack = Stack() From add19ec3fe213f4ac174ce5cf3e24280756a6409 Mon Sep 17 00:00:00 2001 From: Samarpreet Singh <99521823+XxPython28xX@users.noreply.github.com> Date: Sun, 8 Oct 2023 12:49:09 +0530 Subject: [PATCH 03/12] Update stack_using_two_queues.py --- .../stacks/stack_using_two_queues.py | 158 ++++++++++++++---- 1 file changed, 121 insertions(+), 37 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 1cab76afb00c..4284098d3bc5 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,51 +1,135 @@ -class Stack: +from collections import deque + +class StackUsingQueues: + def __init__(self): - self.items = [] + self.queue1 = deque() + self.queue2 = deque() + + def push(self, value: int) -> None: + """ + Pushes an element onto the stack. + + Args: + value (int): The element to push onto the stack. + + Example: + >>> stack = StackUsingQueues() + >>> stack.push(1) + >>> stack.push(2) + >>> stack.push(3) + """ + self.queue2.append(value) + while self.queue1: + self.queue2.append(self.queue1.popleft()) + self.queue1, self.queue2 = self.queue2, self.queue1 + + def pop(self) -> None: + """ + Pops and removes the top element from the stack. + + Example: + >>> stack = StackUsingQueues() + >>> stack.push(1) + >>> stack.push(2) + >>> stack.pop() + """ + if self.queue1: + self.queue1.popleft() + + def top(self) -> int: + """ + Returns the top element of the stack without removing it. - def push(self, item): - self.items.append(item) + Returns: + int: The top element of the stack. + + Example: + >>> stack = StackUsingQueues() + >>> stack.push(1) + >>> stack.push(2) + >>> stack.top() + 2 + """ + if self.queue1: + return self.queue1[0] + return None - def pop(self): - if not self.is_empty(): - return self.items.pop() - else: - return "Stack is empty" + def size(self) -> int: + """ + Returns the current size (number of elements) of the stack. - def peek(self): - if not self.is_empty(): - return self.items[-1] - else: - return "Stack is empty" + Returns: + int: The size of the stack. + + Example: + >>> stack = StackUsingQueues() + >>> stack.size() + 0 + >>> stack.push(1) + >>> stack.push(2) + >>> stack.push(3) + >>> stack.size() + 3 + >>> stack.pop() + >>> stack.size() + 2 + """ + return len(self.queue1) - def is_empty(self): - return len(self.items) == 0 + def is_empty(self) -> bool: + """ + Checks if the stack is empty. - def size(self): - return len(self.items) + Returns: + bool: True if the stack is empty, False otherwise. + + Example: + >>> stack = StackUsingQueues() + >>> stack.is_empty() + True + >>> stack.push(1) + >>> stack.is_empty() + False + """ + return len(self.queue1) == 0 + def peek(self) -> int: + """ + Returns the top element of the stack without removing it. -# Create a stack -stack = Stack() + Returns: + int: The top element of the stack. + + Example: + >>> stack = StackUsingQueues() + >>> stack.push(1) + >>> stack.push(2) + >>> stack.peek() + 2 + """ + if self.queue1: + return self.queue1[0] + return None -# PUSH operation -stack.push(1) -stack.push(2) -stack.push(3) +if __name__ == "__main__": + stack = StackUsingQueues() -# Display the stack -print("Stack:", stack.items) + # Push some elements onto the stack + stack.push(1) + stack.push(2) + stack.push(3) -# POP operation -popped_item = stack.pop() -print("Popped item:", popped_item) + print("Stack size:", stack.size()) + print("Top element:", stack.top()) -# Display the updated stack -print("Stack after POP:", stack.items) + # Pop elements from the stack + stack.pop() + print("Top element after pop:", stack.top()) -# PEEK operation -top_item = stack.peek() -print("Top item (PEEK):", top_item) + stack.pop() + print("Top element after another pop:", stack.top()) -# Check the size of the stack -stack_size = stack.size() -print("Stack size:", stack_size) + print("Is stack empty?", stack.is_empty()) + print("Peek at the top element:", stack.peek()) + print("Final stack size:", stack.size()) From 98bb0706967e997be741ad8f642c31a419323a46 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 07:19:43 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/stacks/stack_using_two_queues.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 4284098d3bc5..633ea6eb01f1 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,7 +1,7 @@ from collections import deque -class StackUsingQueues: +class StackUsingQueues: def __init__(self): self.queue1 = deque() self.queue2 = deque() @@ -12,7 +12,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -43,7 +43,7 @@ def top(self) -> int: Returns: int: The top element of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -61,7 +61,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -83,7 +83,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -100,7 +100,7 @@ def peek(self) -> int: Returns: int: The top element of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -112,6 +112,7 @@ def peek(self) -> int: return self.queue1[0] return None + if __name__ == "__main__": stack = StackUsingQueues() From 6ead57f5d090bddcea599540c9437437deb4dd98 Mon Sep 17 00:00:00 2001 From: Samarpreet Singh <99521823+XxPython28xX@users.noreply.github.com> Date: Sun, 8 Oct 2023 12:52:07 +0530 Subject: [PATCH 05/12] Update stack_using_two_queues.py --- .../stacks/stack_using_two_queues.py | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 633ea6eb01f1..65d001330814 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,10 +1,11 @@ from collections import deque - +from typing import Optional class StackUsingQueues: - def __init__(self): - self.queue1 = deque() - self.queue2 = deque() + + def __init__(self) -> None: + self.queue1: deque = deque() + self.queue2: deque = deque() def push(self, value: int) -> None: """ @@ -12,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -37,13 +38,13 @@ def pop(self) -> None: if self.queue1: self.queue1.popleft() - def top(self) -> int: + def top(self) -> Optional[int]: """ Returns the top element of the stack without removing it. Returns: - int: The top element of the stack. - + int: The top element of the stack, or None if the stack is empty. + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -61,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -83,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -94,13 +95,13 @@ def is_empty(self) -> bool: """ return len(self.queue1) == 0 - def peek(self) -> int: + def peek(self) -> Optional[int]: """ Returns the top element of the stack without removing it. Returns: - int: The top element of the stack. - + int: The top element of the stack, or None if the stack is empty. + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -112,25 +113,6 @@ def peek(self) -> int: return self.queue1[0] return None - if __name__ == "__main__": - stack = StackUsingQueues() - - # Push some elements onto the stack - stack.push(1) - stack.push(2) - stack.push(3) - - print("Stack size:", stack.size()) - print("Top element:", stack.top()) - - # Pop elements from the stack - stack.pop() - print("Top element after pop:", stack.top()) - - stack.pop() - print("Top element after another pop:", stack.top()) - - print("Is stack empty?", stack.is_empty()) - print("Peek at the top element:", stack.peek()) - print("Final stack size:", stack.size()) + import doctest + doctest.testmod() From d195328d03491b6e1c36cc960dc4d8373d0ca60a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 07:22:40 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/stacks/stack_using_two_queues.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 65d001330814..7678ee5da2d9 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,8 +1,8 @@ from collections import deque from typing import Optional -class StackUsingQueues: +class StackUsingQueues: def __init__(self) -> None: self.queue1: deque = deque() self.queue2: deque = deque() @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,6 +113,8 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None + if __name__ == "__main__": import doctest + doctest.testmod() From a04fcae7d3b44c634fc4d11538e153c6a50a588a Mon Sep 17 00:00:00 2001 From: Samarpreet Singh <99521823+XxPython28xX@users.noreply.github.com> Date: Sun, 8 Oct 2023 12:57:22 +0530 Subject: [PATCH 07/12] Update stack_using_two_queues.py --- .../stacks/stack_using_two_queues.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 7678ee5da2d9..c22114cab776 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,11 +1,11 @@ from collections import deque -from typing import Optional - +from typing import Deque, Optional, Union class StackUsingQueues: + def __init__(self) -> None: - self.queue1: deque = deque() - self.queue2: deque = deque() + self.queue1: Deque[int] = deque() + self.queue2: Deque[int] = deque() def push(self, value: int) -> None: """ @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,8 +113,6 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None - if __name__ == "__main__": import doctest - doctest.testmod() From 1b3fba07076cf7dddf08e9877c8b1a1c4443dd67 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 07:28:05 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/stacks/stack_using_two_queues.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index c22114cab776..9955f655c99d 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,8 +1,8 @@ from collections import deque from typing import Deque, Optional, Union -class StackUsingQueues: +class StackUsingQueues: def __init__(self) -> None: self.queue1: Deque[int] = deque() self.queue2: Deque[int] = deque() @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,6 +113,8 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None + if __name__ == "__main__": import doctest + doctest.testmod() From 952b5a4c144e7070ba85bfd6f311c22d3cfbc97d Mon Sep 17 00:00:00 2001 From: Samarpreet Singh <99521823+XxPython28xX@users.noreply.github.com> Date: Sun, 8 Oct 2023 13:00:06 +0530 Subject: [PATCH 09/12] Update stack_using_two_queues.py --- .../stacks/stack_using_two_queues.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 9955f655c99d..94408f5d86a7 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,11 +1,11 @@ from collections import deque -from typing import Deque, Optional, Union - +from typing import Optional class StackUsingQueues: + def __init__(self) -> None: - self.queue1: Deque[int] = deque() - self.queue2: Deque[int] = deque() + self.queue1 = deque() + self.queue2 = deque() def push(self, value: int) -> None: """ @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,8 +113,6 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None - if __name__ == "__main__": import doctest - doctest.testmod() From 4e6c60054786717fa1d9ebf1513cc2a23225a31d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 07:30:39 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/stacks/stack_using_two_queues.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 94408f5d86a7..72edabac3dd6 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,8 +1,8 @@ from collections import deque from typing import Optional -class StackUsingQueues: +class StackUsingQueues: def __init__(self) -> None: self.queue1 = deque() self.queue2 = deque() @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,6 +113,8 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None + if __name__ == "__main__": import doctest + doctest.testmod() From 3403da7eaccfd2ca87ee521705f88b9d2a930111 Mon Sep 17 00:00:00 2001 From: Samarpreet Singh <99521823+XxPython28xX@users.noreply.github.com> Date: Sun, 8 Oct 2023 13:02:27 +0530 Subject: [PATCH 11/12] Update stack_using_two_queues.py --- data_structures/stacks/stack_using_two_queues.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 72edabac3dd6..94408f5d86a7 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,8 +1,8 @@ from collections import deque from typing import Optional - class StackUsingQueues: + def __init__(self) -> None: self.queue1 = deque() self.queue2 = deque() @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,8 +113,6 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None - if __name__ == "__main__": import doctest - doctest.testmod() From 57c235a469291ba7ccf32f579f573d8ab1e5b799 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 07:32:57 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/stacks/stack_using_two_queues.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data_structures/stacks/stack_using_two_queues.py b/data_structures/stacks/stack_using_two_queues.py index 94408f5d86a7..72edabac3dd6 100644 --- a/data_structures/stacks/stack_using_two_queues.py +++ b/data_structures/stacks/stack_using_two_queues.py @@ -1,8 +1,8 @@ from collections import deque from typing import Optional -class StackUsingQueues: +class StackUsingQueues: def __init__(self) -> None: self.queue1 = deque() self.queue2 = deque() @@ -13,7 +13,7 @@ def push(self, value: int) -> None: Args: value (int): The element to push onto the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -44,7 +44,7 @@ def top(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -62,7 +62,7 @@ def size(self) -> int: Returns: int: The size of the stack. - + Example: >>> stack = StackUsingQueues() >>> stack.size() @@ -84,7 +84,7 @@ def is_empty(self) -> bool: Returns: bool: True if the stack is empty, False otherwise. - + Example: >>> stack = StackUsingQueues() >>> stack.is_empty() @@ -101,7 +101,7 @@ def peek(self) -> Optional[int]: Returns: int: The top element of the stack, or None if the stack is empty. - + Example: >>> stack = StackUsingQueues() >>> stack.push(1) @@ -113,6 +113,8 @@ def peek(self) -> Optional[int]: return self.queue1[0] return None + if __name__ == "__main__": import doctest + doctest.testmod()