master > master: code - next greater element messages leicht verbessert

This commit is contained in:
RLogik
2021-11-07 08:50:12 +01:00
parent 8d2de4fa2b
commit cccc6a14ba
3 changed files with 32 additions and 25 deletions

View File

@@ -46,6 +46,7 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
S.INIT();
for i in range(len(L)):
logDebug('Stack S | {S}'.format(S=S));
logDebug('Nächstes List-Element L[{i}] = {el} betrachten'.format(i=i, el=L[i]));
nextElement = L[i];
@@ -54,25 +55,29 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
logDebug('Stack S | {S}'.format(S=S));
while not S.EMPTY():
element = S.TOP();
S.POP();
AddMovesCost();
logDebug('Stack S | {S}; (popped) Top-Element = {el}'.format(S=S, el=element))
# falls element < next Element, zum Output hinzufügen
if element < nextElement:
logDebug('Stack S | {S}; top Element > nextElement; ==> pop und Paar zum Output hinzufügen'.format(S=S))
addToOutput(element, nextElement);
# sonst Element auf Stack zurücklegen und Schleife abbrechen.
else:
logDebug('Stack element >= nextElement ==> zurücklegen')
S.PUSH(element);
S.POP();
AddMovesCost();
break;
logDebug('Stack S | {S}'.format(S=S));
# falls top Element > next Element, auf Stack lassen und Schleife abbrechen.
elif element > nextElement:
break
# falls top Element == next Element, vom Stack entfernen und Schleife abbrechen.
else:
S.POP()
AddMovesCost()
break
logDebug('Stack S | {S}'.format(S=S));
logDebug('L[{i}] auf Stack legen'.format(i=i));
S.PUSH(nextElement);
logDebug('Stack S | {S}'.format(S=S));
AddMovesCost();
logDebug('Stack S | {S}'.format(S=S));
# was übrig bleibt hat kein größeres Element
logDebug('Alles übrige auf Stack hat kein nächstes größeres Element')
while not S.EMPTY():