Skip to content
Snippets Groups Projects
Commit 2d41e901 authored by Manuel Bucher's avatar Manuel Bucher
Browse files

code cleanup

parent 297a2b7d
Branches
No related merge requests found
#!/bin/bash #!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: check <input file>"
exit 0
fi
./loesung <$1 | ./check_result $1 ./loesung <$1 | ./check_result $1
...@@ -55,7 +55,7 @@ typedef struct Field { ...@@ -55,7 +55,7 @@ typedef struct Field {
uint32_t num_odd; uint32_t num_odd;
} Field; } Field;
// returns 0 if successful, nonzero if failed // gibt 0 zurueck, wenn Initialisierung Erfolgreich durchgelaufen ist
int field_init(Field *this) { int field_init(Field *this) {
memset(this, 0, sizeof(Field)); memset(this, 0, sizeof(Field));
this->tiles = malloc(sizeof(Tile)); this->tiles = malloc(sizeof(Tile));
...@@ -64,7 +64,8 @@ int field_init(Field *this) { ...@@ -64,7 +64,8 @@ int field_init(Field *this) {
return this->tiles == 0; return this->tiles == 0;
} }
// if an error occurs, all memory get freed // fuegt p_tile zum dynamischen Array hinzu, im Fehlerfall muss immernoch
// der reservierte Speicher speicher freigegeben werden
int field_push(Field *this, Tile *p_tile) { int field_push(Field *this, Tile *p_tile) {
if (this->size == this->num_tiles) { if (this->size == this->num_tiles) {
if (this->size == 1u<<31) return 1; // catch overflow if (this->size == 1u<<31) return 1; // catch overflow
...@@ -196,10 +197,8 @@ int field_neighbours(Field *this) { ...@@ -196,10 +197,8 @@ int field_neighbours(Field *this) {
top = begin_line; top = begin_line;
begin_line = cur; // neue Zeile begin_line = cur; // neue Zeile
} }
// ermitteln der Zeilen-Beziehung // ermitteln der Zeilen-Beziehung, nur wenn obere Zeile ein ueber der aktuellen ist
if (begin_line != 1 && t[top].x < t[begin_line].x - 1) { if (t[top].x == t[cur].x - 1) {
// Zeilensprung => Warten bis zur naechsten Zeile angekommen
} else if (t[top].x == t[cur].x - 1) {
// finden, ob paar nach oben existiert O(n) fuer alle Nachbarn nach oben/unten. // finden, ob paar nach oben existiert O(n) fuer alle Nachbarn nach oben/unten.
for(;t[top].y < t[cur].y && top < begin_line; top++); for(;t[top].y < t[cur].y && top < begin_line; top++);
......
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
import sys import sys
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
inp = sys.argv[1]
def load(): def main():
if len(sys.argv) != 1:
print("Usage: visualize <input file>")
return
inp = sys.argv[1]
f = open(inp) f = open(inp)
xs = [] xs = []
ys = [] ys = []
...@@ -16,6 +19,6 @@ def load(): ...@@ -16,6 +19,6 @@ def load():
plt.scatter(xs, ys, marker="s") plt.scatter(xs, ys, marker="s")
plt.show() plt.show()
while True: if __name__ == "__main__":
load() main()
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
import sys import sys
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
inp = sys.argv[1]
def load(): def main():
if len(sys.argv) != 1:
print("Usage: visualize <output file>")
return
inp = sys.argv[1]
f = open(inp) f = open(inp)
xs = [] xs = []
ys = [] ys = []
...@@ -19,6 +22,6 @@ def load(): ...@@ -19,6 +22,6 @@ def load():
plt.plot(xs, ys, marker="s") plt.plot(xs, ys, marker="s")
plt.show() plt.show()
while True: if __name__ == "__main__":
load() main()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment