Skip to content

Feature/stack using two queues #10086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
],
"python.analysis.typeCheckingMode": "basic"
}
64 changes: 64 additions & 0 deletions data_structures/stacks/TwoQueuedStack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class StackUsingQueues:
def __init__(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

"""
Initialising required queues using lists data structure
"""
self.queue1 = []
self.queue2 = []

def push(self,item):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file data_structures/stacks/TwoQueuedStack.py, please provide doctest for the function push

Please provide return type hint for the function: push. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: item

while len(self.queue1)!= 0:
"""
enqueuing queue 2 using the values from queue 1 bringing them out in First
In First Out (F.I.F.O) order.
"""
self.queue2.append(self.queue1[0])
self.queue1 .pop(0)
"""
adding the new value to queue 1
"""
self.queue1.append(item)

"""
returning the values from queue 2 to queue 1 so as
to replicate the stack data structure
"""
while len(self.queue2)!= 0:
self.queue1.append(self.queue2[0])
self.queue2.pop(0)




def pop(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file data_structures/stacks/TwoQueuedStack.py, please provide doctest for the function pop

Please provide return type hint for the function: pop. If the function does not return a value, please provide the type hint as: def function() -> None:

if len(self.queue1) != 0:
"""
The first value of queue 1 is being popped here as it
has been implemented in a way that the
first value of the queue which gets popped is the last value of the stack.
And since stack follows Last In First Out (L.I.F.O) order the
following has been implemented.
"""
popped = self.queue1.pop(0)
return popped
else:
return None







def peek(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file data_structures/stacks/TwoQueuedStack.py, please provide doctest for the function peek

Please provide return type hint for the function: peek. If the function does not return a value, please provide the type hint as: def function() -> None:

"""
Function to see the last value inserted in the stack
implemented using queue here, which has the last
value of the stack as its first.
"""
if len(self.queue1) != 0:
return self.queue1[0]
else:
return None