stack_using_two_queues#10002
Closed
IndranjanaChatterjee wants to merge 2 commits intoTheAlgorithms:masterfrom
Closed
stack_using_two_queues#10002IndranjanaChatterjee wants to merge 2 commits intoTheAlgorithms:masterfrom
IndranjanaChatterjee wants to merge 2 commits intoTheAlgorithms:masterfrom
Conversation
for more information, see https://pre-commit.ci
This was referenced Oct 8, 2023
cclauss
requested changes
Oct 8, 2023
Comment on lines
+5
to
+8
| """ Implementing stack using two arrays""" | ||
|
|
||
|
|
||
| class Stack(Generic[T]): # Stack class to implement stack operations |
Member
There was a problem hiding this comment.
Suggested change
| """ Implementing stack using two arrays""" | |
| class Stack(Generic[T]): # Stack class to implement stack operations | |
| class Stack(Generic[T]): | |
| """ Implement a stack using two queues""" | |
| class Stack(Generic[T]): # Stack class to implement stack operations | ||
| def __init__(self) -> None: | ||
| self.insert_queue = deque() # First Queue to be used for inserting | ||
| self.suffle_queue = deque() # Second Queue to be used for suffling |
Member
There was a problem hiding this comment.
OPTIONAL: Should Stack be a dataclass?
| self.suffle_queue = deque() # Second Queue to be used for suffling | ||
|
|
||
| def push(self, item: int) -> None: | ||
| self.insert_queue.append(item) # Add items into the Queue |
Member
There was a problem hiding this comment.
The code already says what the comment repeats.
Suggested change
| self.insert_queue.append(item) # Add items into the Queue | |
| self.insert_queue.append(item) |
Comment on lines
+16
to
+18
| self.insert_queue.append( | ||
| self.suffle_queue.popleft() | ||
| ) # Popping the elements |
Member
There was a problem hiding this comment.
Let's not wrap lines just to make room for a comment.
Suggested change
| self.insert_queue.append( | |
| self.suffle_queue.popleft() | |
| ) # Popping the elements | |
| # Popping the elements | |
| self.insert_queue.append(self.suffle_queue.popleft()) |
| self.insert_queue, self.suffle_queue = self.suffle_queue, self.insert_queue | ||
|
|
||
| def pop(self) -> int: | ||
| if not (self.suffle_queue): # if the stack is empty |
Member
There was a problem hiding this comment.
Suggested change
| if not (self.suffle_queue): # if the stack is empty | |
| if not self.suffle_queue: # if the stack is empty |
Comment on lines
+32
to
+36
| def printing(self) -> None: | ||
| print(self.suffle_queue) | ||
|
|
||
| def size(self) -> int: | ||
| return len(self.suffle_queue) |
Member
There was a problem hiding this comment.
These magic methods will allow us to just print(stack) and len(stack).
Suggested change
| def printing(self) -> None: | |
| print(self.suffle_queue) | |
| def size(self) -> int: | |
| return len(self.suffle_queue) | |
| def __str__(self) -> str: | |
| return tuple(self.suffle_queue) | |
| def __len__(self) -> int: | |
| return len(self.suffle_queue) |
|
|
||
|
|
||
| def test_stack() -> None: | ||
| s = Stack() # Creating a stack in S |
Member
There was a problem hiding this comment.
Single-letter variable names makes code look like it was written in the 1970's.
Suggested change
| s = Stack() # Creating a stack in S | |
| stack = Stack() # Create a empty stack |
14 tasks
Author
Member
|
Fixed in data_structures/stacks/stack_using_two_queues.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Added the code for the implementation of stack using two queues
Fixes:#9987
Checklist: