aboutsummaryrefslogtreecommitdiff
path: root/semestre 3/structures des données/td/td7/exo2.c
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-11-21 18:37:48 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-11-21 18:37:48 +0100
commit20fc727d4f954eb2109b71a7686c3107fdfa4bbf (patch)
treea5613db97e67d8968c7d622b605ed530755176bb /semestre 3/structures des données/td/td7/exo2.c
parent341fc63ff791e08c7d0a00346080067c9bd1d5dd (diff)
Cours du 3 au 21 novembre
ce qui fait 3 semaines en philo et une semaine en info
Diffstat (limited to 'semestre 3/structures des données/td/td7/exo2.c')
-rw-r--r--semestre 3/structures des données/td/td7/exo2.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/semestre 3/structures des données/td/td7/exo2.c b/semestre 3/structures des données/td/td7/exo2.c
new file mode 100644
index 0000000..3e67451
--- /dev/null
+++ b/semestre 3/structures des données/td/td7/exo2.c
@@ -0,0 +1,39 @@
+// complexite = O(2n) = O(n)
+void degre_matrice(int** M, int n, int u, int* deg_e, int* deg_s){
+ for (int i = 0; i < n; i++) if (M[u][i]) (*deg_e)++;
+ for (int i = 0; i < n; i++) if (M[i][u]) (*deg_s)++;
+}
+
+typedef struct Cell{
+ int to;
+ struct Cell* next;
+} Cell;
+
+typedef struct List{
+ int val;
+ Cell* linked;
+} List;
+
+// complexite = O(degre max de n)
+int degre_entrant_LA(List** l, int n, int u){
+ int acc = 0;
+ Cell* c = l[u]->linked;
+ while (c){
+ acc++;
+ c = c->next;
+ }
+ return acc;
+}
+
+// complexite = O(n+(degre max de n))
+int degre_sortant_LA(List** l, int n, int u){
+ int acc = 0;
+ for (int i = 0; i < n; i++){
+ Cell* c = l[i]->linked;
+ while (c){
+ if (c->to == u) acc++;
+ c = c->next;
+ }
+ }
+ return acc;
+}