mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-28 03:48:38 +00:00
Adding more comments
This commit is contained in:
parent
4c4196af9b
commit
885d58f019
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Data object for stack
|
Object stored on the stack
|
||||||
"""
|
"""
|
||||||
class StackData:
|
class StackData:
|
||||||
def __init__(self, current_value: float, min_value: float, max_value: float) -> None:
|
def __init__(self, current_value: float, min_value: float, max_value: float) -> None:
|
||||||
@ -23,6 +23,8 @@ class MinMaxStack:
|
|||||||
|
|
||||||
def push_value(self, value: float) -> bool:
|
def push_value(self, value: float) -> bool:
|
||||||
"""
|
"""
|
||||||
|
Push new value on top of stack
|
||||||
|
|
||||||
>>> test_stack = MinMaxStack(3)
|
>>> test_stack = MinMaxStack(3)
|
||||||
>>> test_stack.push_value(1)
|
>>> test_stack.push_value(1)
|
||||||
True
|
True
|
||||||
@ -53,6 +55,8 @@ class MinMaxStack:
|
|||||||
|
|
||||||
def pop_value(self) -> float:
|
def pop_value(self) -> float:
|
||||||
"""
|
"""
|
||||||
|
Remove the top value from the stack.
|
||||||
|
|
||||||
>>> test_stack = MinMaxStack()
|
>>> test_stack = MinMaxStack()
|
||||||
>>> test_stack.push_value(1)
|
>>> test_stack.push_value(1)
|
||||||
True
|
True
|
||||||
@ -74,6 +78,8 @@ class MinMaxStack:
|
|||||||
|
|
||||||
def get_current_max(self) -> float:
|
def get_current_max(self) -> float:
|
||||||
"""
|
"""
|
||||||
|
Get the highest value on the stack in constant time
|
||||||
|
|
||||||
test_stack = MinMaxStack(3)
|
test_stack = MinMaxStack(3)
|
||||||
>>> test_stack.push_value(-450.45)
|
>>> test_stack.push_value(-450.45)
|
||||||
True
|
True
|
||||||
@ -104,6 +110,8 @@ class MinMaxStack:
|
|||||||
|
|
||||||
def get_current_min(self) -> float:
|
def get_current_min(self) -> float:
|
||||||
"""
|
"""
|
||||||
|
Get the lowest value on the stack in constant time
|
||||||
|
|
||||||
>>> test_stack = MinMaxStack(3)
|
>>> test_stack = MinMaxStack(3)
|
||||||
>>> test_stack.push_value(123)
|
>>> test_stack.push_value(123)
|
||||||
True
|
True
|
||||||
@ -133,6 +141,9 @@ class MinMaxStack:
|
|||||||
return -math.inf
|
return -math.inf
|
||||||
|
|
||||||
def stack_is_valid(self) -> bool:
|
def stack_is_valid(self) -> bool:
|
||||||
|
"""
|
||||||
|
Validate stack is not empty
|
||||||
|
"""
|
||||||
if len(self.stack) == 0:
|
if len(self.stack) == 0:
|
||||||
print("Stack is empty")
|
print("Stack is empty")
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user