master > mater: code - nextGreaterElement, auxiliary methods entfernt

This commit is contained in:
RLogik
2021-11-07 18:56:49 +01:00
parent 3505401c7f
commit 6541a5246d
2 changed files with 9 additions and 48 deletions

View File

@@ -16,7 +16,7 @@ from src.algorithms.methods import *;
# GLOBAL VARIABLES/CONSTANTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_output_list: List[Tuple[int,int]]
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CHECKS
@@ -40,7 +40,7 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
Inputs: L = Liste von Zahlen, x = Zahl.
Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element
'''
clearOutput();
output = [];
S = Stack();
S.INIT();
@@ -58,7 +58,7 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
# falls element < next Element, zum Output hinzufügen und vom Stack entfernen
if element < nextElement:
logDebug('Stack S | {S}; top Element > nextElement; ==> pop und Paar zum Output hinzufügen'.format(S=S))
addToOutput(element, nextElement);
output.append((element, nextElement));
S.POP();
AddMovesCost();
logDebug('Stack S | {S}'.format(S=S));
@@ -85,27 +85,7 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
element = S.TOP();
S.POP();
AddMovesCost();
addToOutput(element, -1);
output.append((element, -1));
logDebug('Stack S | {S}'.format(S=S))
return output();
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# AUXILIARY METHODS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def clearOutput():
global _output_list;
_output_list = [];
return;
def addToOutput(m: int, n: int):
global _output_list;
_output_list.append((m, n))
return;
def output() -> List[Tuple[int, int]]:
global _output_list;
output = _output_list[:] # erstelle Kopie
clearOutput()
return output
return output;