summaryrefslogtreecommitdiff
path: root/math/maxTeilfeld.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-06-27 11:17:34 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-06-27 11:17:34 +0200
commit9e625b89bac7e8daaf583e215f3a0df3dc250bb2 (patch)
treeab295455fce73f726bd97a325a61d95aca77a508 /math/maxTeilfeld.cpp
parent5bb1ac05882e0df43a2afe0c363e0f503f51c357 (diff)
Math section rebuild, merged convinience and sonstiges section.
Diffstat (limited to 'math/maxTeilfeld.cpp')
-rw-r--r--math/maxTeilfeld.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/math/maxTeilfeld.cpp b/math/maxTeilfeld.cpp
index 2b732bb..bbafa3f 100644
--- a/math/maxTeilfeld.cpp
+++ b/math/maxTeilfeld.cpp
@@ -1,14 +1,15 @@
-//N := length of field
+// N := Länge des Feldes.
+// Laufzeit: O(N)
int maxStart = 1, maxLen = 0, curStart = 1, len = 0;
double maxValue = 0, sum = 0;
for (int pos = 0; pos < N; pos++) {
sum += values[pos];
len++;
- if (sum > maxValue) { // neues Maximum
+ if (sum > maxValue) { // Neues Maximum.
maxValue = sum; maxStart = curStart; maxLen = len;
}
- if (sum < 0) { // alles zuruecksetzen
+ if (sum < 0) { // Alles zurücksetzen.
curStart = pos +2; len = 0; sum = 0;
}
}
-//maxSum := maximaler Wert, maxStart := Startposition, maxLen := Laenge der Sequenz \ No newline at end of file
+// maxSum := maximaler Wert, maxStart := Startposition, maxLen := Länge der Sequenz