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

ueberlauf vermieden

parent 621400cb
Branches
No related merge requests found
...@@ -106,17 +106,17 @@ void list_free(List *this) { ...@@ -106,17 +106,17 @@ void list_free(List *this) {
/** pruefen, ob genausoviele gerade und ungerade Kacheln existieren, /** pruefen, ob genausoviele gerade und ungerade Kacheln existieren,
* ohne einen Overflow zu erzeugen * ohne einen Overflow zu erzeugen
* notwendiges Kriterium fuer unzusammenhaengender graph und hinreichendes * notwendiges Kriterium fuer
* fuer zusammenhaengender
*/ */
bool list_possible(List *this) { bool list_necessity(List *this) {
return this->num_tiles - this->num_odd == this->num_odd; return this->num_tiles - this->num_odd == this->num_odd;
} }
/** Zurueckgeben, ob graph ein vollstaendiges Rechteck ist */ /** Zurueckgeben, ob graph ein vollstaendiges Rechteck ist */
bool list_rectangle(List *this) { bool list_rectangle(List *this) {
return (this->max.x - this->min.x) * (this->max.y - this->min.y) // verwenden von `uint64_t` um einen ueberlauf zu vermeiden
== this->num_tiles; // TODO: check for overflow? return (uint64_t)(this->max.x - this->min.x) * (uint64_t)(this->max.y - this->min.y)
== (uint64_t)this->num_tiles;
} }
typedef enum ReadResult { typedef enum ReadResult {
...@@ -349,6 +349,17 @@ int main (void) ...@@ -349,6 +349,17 @@ int main (void)
list_free(&tile_list); list_free(&tile_list);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!list_necessity(&tile_list)) {
printf("None\n");
return EXIT_SUCCESS;
}
if (list_rectangle(&tile_list)) {
printf("Rechteck");
// TODO: Rechteck ausgabefunktion
return EXIT_SUCCESS;
}
Array tile_array; Array tile_array;
// uebertragen der Liste in ein Array, und uebergeben des ownership der Tiles // uebertragen der Liste in ein Array, und uebergeben des ownership der Tiles
// an das Array // an das Array
...@@ -358,9 +369,6 @@ int main (void) ...@@ -358,9 +369,6 @@ int main (void)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// TODO: pruefen, ob notwendiges Kriterium erfuellt,
// TODO: Falls Rechteck, dieses Ausgeben.
//array_print(&tile_array); //array_print(&tile_array);
qsort(tile_array.tiles, tile_array.num_tiles, sizeof(Tile*), tile_compare); qsort(tile_array.tiles, tile_array.num_tiles, sizeof(Tile*), tile_compare);
......
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