data_structures.stacks.stack_tracking_min_max ============================================= .. py:module:: data_structures.stacks.stack_tracking_min_max Classes ------- .. autoapisummary:: data_structures.stacks.stack_tracking_min_max.MinMaxStack data_structures.stacks.stack_tracking_min_max.StackData Module Contents --------------- .. py:class:: MinMaxStack(max_stack_size: int = 10) Main stack implementation .. py:method:: get_current_max() -> float Get the highest value on the stack in constant time >>> test_stack = MinMaxStack(3) >>> test_stack.push_value(-450.45) True >>> test_stack.push_value(450.45) True >>> test_stack.push_value(0) True >>> test_stack.get_current_max() 450.45 >>> test_stack.pop_value() 0 >>> test_stack.get_current_max() 450.45 >>> test_stack.pop_value() 450.45 >>> test_stack.get_current_max() -450.45 >>> test_stack.pop_value() -450.45 >>> test_stack.get_current_max() Stack is empty -inf .. py:method:: get_current_min() -> float Get the lowest value on the stack in constant time >>> test_stack = MinMaxStack(3) >>> test_stack.push_value(123) True >>> test_stack.push_value(-123) True >>> test_stack.push_value(0) True >>> test_stack.get_current_min() -123 >>> test_stack.pop_value() 0 >>> test_stack.get_current_min() -123 >>> test_stack.pop_value() -123 >>> test_stack.get_current_min() 123 >>> test_stack.pop_value() 123 >>> test_stack.get_current_min() Stack is empty -inf .. py:method:: pop_value() -> float Remove the top value from the stack. >>> test_stack = MinMaxStack() >>> test_stack.push_value(1) True >>> test_stack.push_value(2) True >>> test_stack.pop_value() 2 >>> test_stack.pop_value() 1 >>> test_stack.pop_value() Stack is empty -inf .. py:method:: push_value(value: float) -> bool Push new value on top of stack >>> test_stack = MinMaxStack(3) >>> test_stack.push_value(1) True >>> test_stack.push_value(2) True >>> test_stack.push_value(3) True >>> test_stack.push_value(4) Traceback (most recent call last): ... Exception: Max stack size reached. .. py:method:: stack_is_valid() -> bool Validate stack is not empty >>> test_stack = MinMaxStack(3) >>> test_stack.stack_is_valid() Stack is empty False >>> test_stack.push_value(0) True >>> test_stack.stack_is_valid() True .. py:attribute:: max_size :value: 10 .. py:attribute:: stack :type: list[StackData] :value: [] .. py:class:: StackData(current_value: float, min_value: float, max_value: float) Object stored on the stack .. py:attribute:: current_value .. py:attribute:: max_value .. py:attribute:: min_value