-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
added stack_using_two_queues.py #10080
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 1 commit
8ebf863
494e92f
add19ec
98bb070
6ead57f
d195328
a04fcae
1b3fba0
952b5a4
4e6c600
3403da7
57c235a
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class Stack: | ||
def __init__(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. Please provide return type hint for the function: |
||
self.items = [] | ||
|
||
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: |
||
self.items.append(item) | ||
|
||
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 not self.is_empty(): | ||
return self.items.pop() | ||
else: | ||
return "Stack is empty" | ||
|
||
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: |
||
if not self.is_empty(): | ||
return self.items[-1] | ||
else: | ||
return "Stack is empty" | ||
|
||
def is_empty(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: |
||
return len(self.items) == 0 | ||
|
||
def size(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: |
||
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) |
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: