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

* Add typing

hacktoberfest

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Saksham Chawla 2022-10-12 22:14:08 +05:30 committed by GitHub
parent aeb933bff5
commit e272b9d6a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
"""Queue represented by a pseudo stack (represented by a list with pop and append)""" """Queue represented by a pseudo stack (represented by a list with pop and append)"""
from typing import Any
class Queue: class Queue:
@ -14,7 +15,7 @@ class Queue:
@param item @param item
item to enqueue""" item to enqueue"""
def put(self, item): def put(self, item: Any) -> None:
self.stack.append(item) self.stack.append(item)
self.length = self.length + 1 self.length = self.length + 1
@ -23,7 +24,7 @@ class Queue:
@return dequeued @return dequeued
item that was dequeued""" item that was dequeued"""
def get(self): def get(self) -> Any:
self.rotate(1) self.rotate(1)
dequeued = self.stack[self.length - 1] dequeued = self.stack[self.length - 1]
self.stack = self.stack[:-1] self.stack = self.stack[:-1]
@ -35,7 +36,7 @@ class Queue:
@param rotation @param rotation
number of times to rotate queue""" number of times to rotate queue"""
def rotate(self, rotation): def rotate(self, rotation: int) -> None:
for i in range(rotation): for i in range(rotation):
temp = self.stack[0] temp = self.stack[0]
self.stack = self.stack[1:] self.stack = self.stack[1:]
@ -45,7 +46,7 @@ class Queue:
"""Reports item at the front of self """Reports item at the front of self
@return item at front of self.stack""" @return item at front of self.stack"""
def front(self): def front(self) -> Any:
front = self.get() front = self.get()
self.put(front) self.put(front)
self.rotate(self.length - 1) self.rotate(self.length - 1)
@ -53,5 +54,5 @@ class Queue:
"""Returns the length of this.stack""" """Returns the length of this.stack"""
def size(self): def size(self) -> int:
return self.length return self.length