-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Changes from 2 commits
c36e0c4
860cc55
db8e457
847721f
979bf79
609aeff
24931d3
9beb2ea
d68b408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"githubPullRequests.ignoredPullRequestBranches": [ | ||
"master" | ||
] | ||
], | ||
"python.analysis.typeCheckingMode": "basic" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class StackUsingQueues: | ||
def __init__(self): | ||
""" | ||
Initialising required queues using lists data structure | ||
""" | ||
self.queue1 = [] | ||
self.queue2 = [] | ||
|
||
def push(self,item): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide return type hint for the function: Please provide type hint for the parameter: |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide return type hint for the function: |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide return type hint for the function: |
||
""" | ||
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 | ||
|
||
|
There was a problem hiding this comment.
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: