Skip to content

Add typing to data_structures/queue/queue_on_pseudo_stack.py #7037

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

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Changes from all 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
11 changes: 6 additions & 5 deletions data_structures/queue/queue_on_pseudo_stack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Queue represented by a pseudo stack (represented by a list with pop and append)"""
from typing import Any


class Queue:
Expand All @@ -14,7 +15,7 @@ def __str__(self):
@param item
item to enqueue"""

def put(self, item):
def put(self, item: Any) -> None:
self.stack.append(item)
self.length = self.length + 1

Expand All @@ -23,7 +24,7 @@ def put(self, item):
@return dequeued
item that was dequeued"""

def get(self):
def get(self) -> Any:
self.rotate(1)
dequeued = self.stack[self.length - 1]
self.stack = self.stack[:-1]
Expand All @@ -35,7 +36,7 @@ def get(self):
@param rotation
number of times to rotate queue"""

def rotate(self, rotation):
def rotate(self, rotation: int) -> None:
for i in range(rotation):
temp = self.stack[0]
self.stack = self.stack[1:]
Expand All @@ -45,13 +46,13 @@ def rotate(self, rotation):
"""Reports item at the front of self
@return item at front of self.stack"""

def front(self):
def front(self) -> Any:
front = self.get()
self.put(front)
self.rotate(self.length - 1)
return front

"""Returns the length of this.stack"""

def size(self):
def size(self) -> int:
return self.length