Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-controle_continue_3
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
dario.genga
progseq-controle_continue_3
Commits
9cf596f4
Commit
9cf596f4
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add unfinished ex 4 and 5
parent
bbf5f2d9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ex4/ex4.c
+87
-0
87 additions, 0 deletions
ex4/ex4.c
ex5/ex5.c
+114
-1
114 additions, 1 deletion
ex5/ex5.c
with
201 additions
and
1 deletion
ex4/ex4.c
+
87
−
0
View file @
9cf596f4
...
@@ -8,6 +8,93 @@
...
@@ -8,6 +8,93 @@
#include
<string.h>
#include
<string.h>
#include
<stdbool.h>
#include
<stdbool.h>
#define QUADTREE_SIZE 16
typedef
struct
_node
{
int
info
;
struct
_node
*
child
[
4
];
// or struct _node **child;
}
node
;
bool
is_leaf
(
node
*
tree
)
{
return
(
NULL
==
tree
->
child
[
0
]);
}
int
max
(
int
x
,
int
y
)
{
return
(
x
>=
y
?
x
:
y
);
}
int
max_depth
(
int
depths
[
4
])
{
int
m
=
depths
[
0
];
for
(
int
i
=
1
;
i
<
4
;
++
i
)
{
m
=
max
(
m
,
depths
[
i
]);
}
return
m
;
}
int
depth
(
node
*
qt
)
{
int
depths
[]
=
{
0
,
0
,
0
,
0
};
if
(
is_leaf
(
qt
))
{
return
0
;
}
else
{
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
depths
[
i
]
=
depth
(
qt
->
child
[
i
]);
}
return
1
+
max_depth
(
depths
);
}
}
node
*
qt_create
(
int
depth
)
{
node
*
n
=
calloc
(
1
,
sizeof
(
node
));
if
(
depth
>
0
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
n
->
child
[
i
]
=
qt_create
(
depth
-
1
);
}
}
return
n
;
}
node
*
position
(
int
row
,
int
col
,
node
*
tree
)
{
int
d
=
depth
(
tree
);
while
(
d
>
1
)
{
int
index
=
2
*
((
row
%
(
int
)
pow
(
2
,
d
))
/
(
int
)
pow
(
2
,
(
d
-
1
)))
+
(
col
%
(
int
)
pow
(
2
,
d
))
/
(
int
)
pow
(
2
,
(
d
-
1
));
tree
=
tree
->
child
[
index
];
d
-=
1
;
}
return
tree
;
}
node
*
create_tree_from_matrix
(
int
nb_row
,
int
nb_col
,
int
matrix
[
nb_row
][
nb_col
],
int
depth
)
{
node
*
qt
=
qt_create
(
depth
);
for
(
int
row
=
0
;
row
<
nb_row
;
row
++
)
{
for
(
int
col
=
0
;
col
<
nb_col
;
col
++
)
{
node
*
current
=
position
(
row
,
col
,
qt
);
current
->
info
=
matrix
[
row
][
col
];
}
}
return
qt
;
}
int
main
()
{
int
main
()
{
int
row
=
QUADTREE_SIZE
;
int
col
=
QUADTREE_SIZE
;
int
matrix
[
16
][
16
]
=
{
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
3
,
3
,
0
,
0
,
0
,
7
,
7
,
7
,
0
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
3
,
3
,
0
,
0
,
0
,
7
,
7
,
7
,
0
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
}
};
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
This diff is collapsed.
Click to expand it.
ex5/ex5.c
+
114
−
1
View file @
9cf596f4
/* Author : Dario GENGA
/* Author : Dario GENGA
* Date : 03.05.2022
* Date : 03.05
.2022
* Description : Contrôle continue 3 - Exercice 5
* Description : Contrôle continue 3 - Exercice 5
*/
*/
...
@@ -7,7 +7,120 @@
...
@@ -7,7 +7,120 @@
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
#include
<stdbool.h>
#include
<stdbool.h>
#include
<math.h>
#define QUADTREE_SIZE 16
typedef
struct
_node
{
int
info
;
struct
_node
*
child
[
4
];
// or struct _node **child;
}
node
;
bool
is_leaf
(
node
*
tree
)
{
return
(
NULL
==
tree
->
child
[
0
]);
}
int
max
(
int
x
,
int
y
)
{
return
(
x
>=
y
?
x
:
y
);
}
int
max_depth
(
int
depths
[
4
])
{
int
m
=
depths
[
0
];
for
(
int
i
=
1
;
i
<
4
;
++
i
)
{
m
=
max
(
m
,
depths
[
i
]);
}
return
m
;
}
int
depth
(
node
*
qt
)
{
int
depths
[]
=
{
0
,
0
,
0
,
0
};
if
(
is_leaf
(
qt
))
{
return
0
;
}
else
{
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
depths
[
i
]
=
depth
(
qt
->
child
[
i
]);
}
return
1
+
max_depth
(
depths
);
}
}
node
*
qt_create
(
int
depth
)
{
node
*
n
=
calloc
(
1
,
sizeof
(
node
));
if
(
depth
>
0
)
{
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
n
->
child
[
i
]
=
qt_create
(
depth
-
1
);
}
}
return
n
;
}
node
*
position
(
int
row
,
int
col
,
node
*
tree
)
{
int
d
=
depth
(
tree
);
while
(
d
>
1
)
{
int
index
=
2
*
((
row
%
(
int
)
pow
(
2
,
d
))
/
(
int
)
pow
(
2
,
(
d
-
1
)))
+
(
col
%
(
int
)
pow
(
2
,
d
))
/
(
int
)
pow
(
2
,
(
d
-
1
));
tree
=
tree
->
child
[
index
];
d
-=
1
;
}
return
tree
;
}
node
*
create_tree_from_matrix
(
int
nb_row
,
int
nb_col
,
int
matrix
[
nb_row
][
nb_col
],
int
depth
)
{
node
*
qt
=
qt_create
(
depth
);
for
(
int
row
=
0
;
row
<
nb_row
;
row
++
)
{
for
(
int
col
=
0
;
col
<
nb_col
;
col
++
)
{
node
*
current
=
position
(
row
,
col
,
qt
);
current
->
info
=
matrix
[
row
][
col
];
}
}
return
qt
;
}
void
transform
(
node
*
qt
,
int
size
,
int
indices
[
size
])
{
node
*
current
=
qt
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
current
=
qt
->
child
[
indices
[
i
]];
int
childs
[
4
]
=
{
current
->
child
[
0
]
->
info
,
current
->
child
[
1
]
->
info
,
current
->
child
[
2
]
->
info
,
current
->
child
[
3
]
->
info
,
};
int
max
=
max_depth
(
childs
);
}
}
int
main
()
{
int
main
()
{
int
row
=
QUADTREE_SIZE
;
int
col
=
QUADTREE_SIZE
;
int
matrix
[
16
][
16
]
=
{
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
3
,
3
,
0
,
0
,
0
,
7
,
7
,
7
,
0
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
3
,
3
,
0
,
0
,
0
,
7
,
7
,
7
,
0
,
0
,
0
,
11
,
11
,
11
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
0
,
0
,
0
,
0
,
0
,
11
,
0
,
0
},
{
0
,
3
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
},
{
0
,
3
,
3
,
3
,
3
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
11
,
11
,
11
}
};
int
parcours
[
2
]
=
{
3
,
1
};
node
*
qTree
=
create_tree_from_matrix
(
row
,
col
,
matrix
,
4
);
transform
(
qTree
,
3
,
parcours
);
for
(
int
r
=
0
;
r
<
row
;
r
++
)
{
for
(
int
c
=
0
;
c
<
col
;
c
++
)
{
printf
(
"%d "
,
matrix
[
r
][
c
]);
}
printf
(
"
\n
"
);
}
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
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