Skip to content

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

Closed
wants to merge 12 commits into from
50 changes: 50 additions & 0 deletions data_structures/stacks/stack_using_two_queues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Stack:
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:

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:

self.items = []

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/stack_using_two_queues.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

self.items.append(item)

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/stack_using_two_queues.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 not self.is_empty():
return self.items.pop()
else:
return "Stack is empty"

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/stack_using_two_queues.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:

if not self.is_empty():
return self.items[-1]
else:
return "Stack is empty"

def is_empty(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/stack_using_two_queues.py, please provide doctest for the function is_empty

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

return len(self.items) == 0

def size(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/stack_using_two_queues.py, please provide doctest for the function size

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

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)