Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controle-c-002
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
controle-c-002
Commits
19c4eeaa
Commit
19c4eeaa
authored
3 years ago
by
florian.burgener
Browse files
Options
Downloads
Patches
Plain Diff
Validation ex4
parent
aa10b067
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ex4/ex4.c
+46
-3
46 additions, 3 deletions
ex4/ex4.c
with
46 additions
and
3 deletions
ex4/ex4.c
+
46
−
3
View file @
19c4eeaa
...
...
@@ -9,18 +9,21 @@
*
*/
#include
<math.h>
#include
<stdbool.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
typedef
struct
Point
{
int32_t
x
;
int32_t
y
;
}
Point
;
/**
* @brief Read the points that are in the input.
*
* @param points_length
* @return Point**
*/
Point
**
read_points_from_input
(
int32_t
points_length
)
{
Point
**
points
=
(
Point
**
)
malloc
(
sizeof
(
Point
)
*
points_length
);
...
...
@@ -33,6 +36,13 @@ Point **read_points_from_input(int32_t points_length) {
return
points
;
}
/**
* @brief Create a new matrix of size row x column.
*
* @param row_count
* @param column_count
* @return int32_t**
*/
int32_t
**
new_matrix
(
int32_t
row_count
,
int32_t
column_count
)
{
int32_t
**
matrix
=
(
int32_t
**
)
malloc
(
sizeof
(
int32_t
*
)
*
row_count
);
...
...
@@ -43,10 +53,24 @@ int32_t **new_matrix(int32_t row_count, int32_t column_count) {
return
matrix
;
}
/**
* @brief Calculate the distance between two points.
*
* @param p1
* @param p2
* @return int32_t
*/
int32_t
calculate_distance
(
Point
*
p1
,
Point
*
p2
)
{
return
abs
(
p2
->
x
-
p1
->
x
)
+
abs
(
p2
->
y
-
p1
->
y
);
}
/**
* @brief Calculates all possible distances with the list of points.
*
* @param distances
* @param points
* @param points_length
*/
void
compute_distances
(
int32_t
**
distances
,
Point
**
points
,
int32_t
points_length
)
{
for
(
int32_t
i
=
0
;
i
<
points_length
;
i
+=
1
)
{
for
(
int32_t
j
=
0
;
j
<
points_length
;
j
+=
1
)
{
...
...
@@ -55,6 +79,13 @@ void compute_distances(int32_t **distances, Point **points, int32_t points_lengt
}
}
/**
* @brief Displays the matrix.
*
* @param matrix
* @param row_count
* @param column_count
*/
void
print_matrix
(
int32_t
**
matrix
,
int32_t
row_count
,
int32_t
column_count
)
{
for
(
int32_t
i
=
0
;
i
<
row_count
;
i
+=
1
)
{
for
(
int32_t
j
=
0
;
j
<
column_count
;
j
+=
1
)
{
...
...
@@ -65,6 +96,12 @@ void print_matrix(int32_t **matrix, int32_t row_count, int32_t column_count) {
}
}
/**
* @brief Deletes the matrix from the memory.
*
* @param matrix
* @param row_count
*/
void
delete_matrix
(
int32_t
**
matrix
,
int32_t
row_count
)
{
for
(
int32_t
i
=
0
;
i
<
row_count
;
i
+=
1
)
{
free
(
matrix
[
i
]);
...
...
@@ -73,6 +110,12 @@ void delete_matrix(int32_t **matrix, int32_t row_count) {
free
(
matrix
);
}
/**
* @brief Deletes the points from the memory.
*
* @param points
* @param points_length
*/
void
delete_points
(
Point
**
points
,
int32_t
points_length
)
{
for
(
int32_t
i
=
0
;
i
<
points_length
;
i
+=
1
)
{
free
(
points
[
i
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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