Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dsprog
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Manuel Bucher
dsprog
Commits
4fe692fe
Commit
4fe692fe
authored
6 years ago
by
Manuel Bucher
Browse files
Options
Downloads
Patches
Plain Diff
ueberlauf vermieden
parent
621400cb
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
loesung.c
+16
-8
16 additions, 8 deletions
loesung.c
with
16 additions
and
8 deletions
loesung.c
+
16
−
8
View file @
4fe692fe
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment