amsi@ai.univ-paris8.fr



Documents pareils
Brefs rappels sur la pile et le tas (Stack. / Heap) et les pointeurs

Les structures de données. Rajae El Ouazzani

#include <stdio.h> #include <stdlib.h> struct cell { int clef; struct cell *suiv; };

Centre CPGE TSI - Safi 2010/2011. Algorithmique et programmation :

Archivage Messagerie Evolution pour usage HTML en utilisant Hypermail

Cours d Algorithmique-Programmation 2 e partie (IAP2): programmation 24 octobre 2007impérative 1 / 44 et. structures de données simples

1. Structure d un programme C. 2. Commentaire: /*..texte */ On utilise aussi le commentaire du C++ qui est valable pour C: 3.

Les arbres binaires de recherche

Cours Programmation Système

MINIMUM. connaissances nécessaires à la programmation des microcontrôleurs PIC18 en langage C (une introduction au langage c A.N.S.

DNS Server RPC Interface buffer overflow. Céline COLLUMEAU Nicolas BODIN

Cours de Programmation Impérative: Zones de mémoires et pointeurs

Algorithmique, Structures de données et langage C

Travaux pratiques. Compression en codage de Huffman Organisation d un projet de programmation

Programmation en langage C

Prénom : Matricule : Sigle et titre du cours Groupe Trimestre INF1101 Algorithmes et structures de données Tous H2004. Loc Jeudi 29/4/2004

Chapitre 1 : La gestion dynamique de la mémoire

Table des matières. Chapitre 4 : Variables pointeurs

INITIATION A LA PROGRAMMATION

Initiation. àl algorithmique et à la programmation. en C

Cours de C. Petits secrets du C & programmation avancée. Sébastien Paumier

DE L ALGORITHME AU PROGRAMME INTRO AU LANGAGE C 51

INF 104 (SELC) Introduction au langage C

Compression de Données - Algorithme de Huffman Document de Conception

03/04/2007. Tâche 1 Tâche 2 Tâche 3. Système Unix. Time sharing

Gestion de la mémoire

Cours de C. Allocation dynamique. Sébastien Paumier

Le prototype de la fonction main()

Pensez à vous inscrire... si ce n est pas encore fait

Conventions d écriture et outils de mise au point

TP2 : tableaux dynamiques et listes chaînées

Le système de gestion des fichiers, les entrées/sorties.

INF111. Initiation à la programmation impérative en C amini/cours/l1/inf111/ Massih-Reza Amini

Le Langage C Version 1.2 c 2002 Florence HENRY Observatoire de Paris Université de Versailles florence.henry@obspm.fr

TD2/TME2 : Ordonnanceur et Threads (POSIX et fair)

Quelques éléments de compilation en C et makefiles

Programmation système de commandes en C

Programmation en C. École Nationale Supérieure de Techniques Avancées. Pierre-Alain Fouque et David Pointcheval

3IS - Système d'exploitation linux - Programmation système

OS Réseaux et Programmation Système - C5

Les processus légers : threads. Système L3, /31

Les structures. Chapitre 3

Projet de programmation (IK3) : TP n 1 Correction

Outils pour la pratique

Algorithmique I. Algorithmique I p.1/??

Algorithmique et Programmation, IMA

Département Automatisation et Informatisation Année Programmation en C++ Institut des Sciences et Techniques de l Ingénieur d Angers

1/24. I passer d un problème exprimé en français à la réalisation d un. I expressions arithmétiques. I structures de contrôle (tests, boucles)

Notes du cours 4M056 Programmation en C et C++ Vincent Lemaire et Damien Simon

Programmation en langage C Eléments de syntaxe

LE LANGAGE C++ ENAC 1997 A. DANCEL

30.avr.10 Présentation miniprojet. 9.mars.10 Cours 3 4.mai.10 Cours C mars.10 Cours 4 11.mai.10 Cours C++ 2

Introduction au langage C

Arbres binaires de recherche

Programmation Structurée Langage C

Génération de code binaire pour application multimedia : une approche au vol

Programmation C. J.-F. Lalande. 15 novembre 2012

EPREUVE OPTIONNELLE d INFORMATIQUE CORRIGE

Les processus. Système L3, /39

Langage C. Patrick Corde. 22 juin Patrick Corde ( Patrick.Corde@idris.fr ) Langage C 22 juin / 289

Algorithmique & Langage C IUT GEII S1. Notes de cours (première partie) cours_algo_lgc1.17.odp. Licence

Cours d initiation à la programmation en C++ Johann Cuenin

Seance 2: En respectant la méthode de programmation par contrat, implémentez les autres fonctions de jeu.

INTRODUCTION À LA PROGRAMMATION CONCURRENTE

C++ Programmer. en langage. 8 e édition. Avec une intro aux design patterns et une annexe sur la norme C++11. Claude Delannoy

Java Licence Professionnelle CISII,

Resolution limit in community detection

ETUDE DE CAS en UML : GESTION DES COMMANDES DE PIECES FABRIQUEES PAR LA SOCIETE C

1.6- Génération de nombres aléatoires

Chaîne de production d un programme

Derrière toi Une machine virtuelle!

Cours de C++ François Laroussinie. 2 novembre Dept. d Informatique, ENS de Cachan

Cours Langage C/C++ Programmation modulaire

Exécutif temps réel Pierre-Yves Duval (cppm)

Cours d Algorithmique et de Langage C v 3.0

Travaux Dirigés n 1 : chaînes de caractères

Gestion mémoire et Représentation intermédiaire

Le langage C. Séance n 4

SUPPORT DE COURS. Langage C

SUPPORT DE COURS. Dr. Omari Mohammed Maître de Conférences Classe A Université d Adrar Courriel : omarinmt@gmail.com

COURS D'INFORMATIQUE: LANGAGE C NOTES DE COURS

TRAVAUX PRATIQUES Programmation Système Langage C / Système UNIX. 2 e année Génie Informatique

Programmation système I Les entrées/sorties

BTS IRIS Cours et Travaux Pratiques. Programmation C. A. Lebret, TSIRIS, Lycée Diderot, 1995/06. en conformité avec le référentiel du BTS IRIS

Cours de programmation avancée. Le langage C. Université du Luxembourg

Introduction à la programmation orientée objet, illustrée par le langage C++ Patrick Cégielski

Introduction au Langage de Programmation C

Éléments d informatique Cours 3 La programmation structurée en langage C L instruction de contrôle if

MISE A NIVEAU INFORMATIQUE LANGAGE C - EXEMPLES DE PROGRAMMES. Université Paris Dauphine IUP Génie Mathématique et Informatique 2 ème année

Univers de murs et arbre BSP

Architecture des ordinateurs

Cours 6 : Tubes anonymes et nommés

V- Manipulations de nombres en binaire

Dans le chapitre 1, nous associions aux fichiers ouverts des descripteurs de fichiers par lesquels nous accédions aux fichiers.

Cours intensif Java. 1er cours: de C à Java. Enrica DUCHI LIAFA, Paris 7. Septembre Enrica.Duchi@liafa.jussieu.fr

IN Cours 1. 1 Informatique, calculateurs. 2 Un premier programme en C

INITIATION AU LANGAGE C SUR PIC DE MICROSHIP

COURS DE LANGAGE C. DIAO Oumar. Université de Rennes 1. Master 1

UE C avancé cours 1: introduction et révisions

Bases de programmation. Cours 5. Structurer les données

Transcription:

1 #ifndef TOOLS_H 3 #define TOOLS_H 4 typedef struct node_t { 6 int id; 7 struct node_t * fg, *fd; 8 } node_t; 9 #define N 6 10 #define MAX(a, b) ((a) > (b)? (a) : (b)) 11 1 extern void push(node_t * v); 13 extern node_t * pop(void); 14 extern int empty(void); 1 extern void enfiler(int v); 16 extern int defiler(void); 17 extern int vide(void); 18 19 #endif 1 #include "tools.h" 3 static int haut = 0, file[n + 1], debut = 0, fin = 0; 4 static node_t * pile[n]; 6 extern void push(node_t * v) { 7 pile[haut++] = v; 8 } 9 extern node_t * pop(void) { 10 return pile[--haut]; 11 } 1 extern int empty(void) { 13 return!haut; 14 } 1 extern void enfiler(int v) { 16 file[fin++] = v; 17 if(fin > N) 18 fin = 0; 19 } 0 extern int defiler(void) { 1 int v = file[debut++]; if(debut > N) 3 debut = 0; 4 return v; } 6 extern int vide(void) { 7 return debut == fin; 8 } Figure 1 Arbres binaires, piles et files (fichiers tool.h et tool.c) 1

1 #include "tools.h" #include <stdio.h> 3 #include <stdlib.h> 4 #include <assert.h> 6 node_t * newnode(int id) { 7 node_t * n = malloc(1 * sizeof *n); assert(n); 8 n->id = id; n->fg = n->fd = NULL; 9 return n; 10 } 11 node_t ** findposition(int id, node_t ** tree) { 1 if(*tree == NULL) return tree; 13 if(id < (*tree)->id) return findposition(id, &((*tree)->fg)); 14 return findposition(id, &((*tree)->fd)); 1 } 16 void printtree(node_t * ptr) { 17 if(ptr == NULL) return; 18 printtree(ptr->fg); printf("%d ", ptr->id); printtree(ptr->fd); 19 } 0 void printtreep(node_t * ptr) { 1 while(ptr!= NULL!empty()) { if(ptr) { 3 push(ptr); 4 ptr = ptr->fg; continue; 6 } else 7 ptr = pop(); 8 printf("%d ", ptr->id); 9 ptr = ptr->fd; 30 } 31 } 3 void treefile(node_t * ptr) { 33 if(ptr == NULL) return; 34 treefile(ptr->fg); enfiler(ptr->id); treefile(ptr->fd); 3 } 36 void printfile() { 37 while(!vide()) printf("%d ", defiler()); 38 printf("\n"); 39 } 40 int maxdepth(node_t * ptr, int cd) { 41 int a, b; 4 if(ptr == NULL) return cd; 43 a = maxdepth(ptr->fg, ++cd); b = maxdepth(ptr->fd, cd); 44 return MAX(a, b); 4 } 46 void freetree(node_t * ptr) { 47 node_t * tmp; 48 if(ptr == NULL) return; 49 freetree(ptr->fg); 0 tmp = ptr->fd; 1 free(ptr); freetree(tmp); } 3 int main(void) { 4 node_t * a = NULL; int i, n = 100, v; 6 for(i = 0; i < n; i++) { 7 v = n * (rand() / (RAND_MAX + 1.0)); 8 *(findposition(v, &a)) = newnode(v); 9 } 60 v = maxdepth(a, 0); assert(v <= N); 61 printf("profondeur de l arbre : %d\n", v); 6 /* Imprimer l arbre récursivement */ 63 printtree(a); printf("\n"); 64 /* Imprimer l arbre en utilisant Notre PILE */ 6 printtreep(a); printf("\n"); 66 /* Utiliser Notre FILE */ 67 treefile(a); printfile(); 68 /* Libérer l arbre */ 69 freetree(a); a = NULL; 70 return 0; 71 } Figure Arbres binaires, piles et files (fichier ab.c)

1 digraph G { A [shape=rect]; 3 A -> B; 4 B -> C; C -> D; 6 D -> A; 7 } Figure 3 Exemple de description de graphe avec GraphViz A B C D Figure 4 Résultat obtenu pour l exemple Figure 3 1 digraph G { A [shape=box]; 3 B [label="je change de nom"]; 4 C [color=red]; A -> B; 6 B -> C; 7 C -> D; 8 D -> A [style=dotted]; 9 } Figure Autre exemple de description de graphe avec GraphViz A Je change de nom C D Figure 6 Résultat obtenu pour l exemple Figure 3

1 #include <time.h> #include <stdio.h> 3 #include <stdlib.h> 4 #include <assert.h> typedef struct node_t node_t; 6 struct node_t { 7 int id; 8 struct node_t * fg, *fd; 9 }; 10 #define MAX(a, b) ((a) > (b)? (a) : (b)) 11 node_t * newnode(int id) { 1 node_t * n = malloc(1 * sizeof *n); assert(n); 13 n->id = id; n->fg = n->fd = NULL; 14 return n; 1 } 16 node_t ** findposition(int id, node_t ** tree) { 17 if(*tree == NULL) return tree; 18 if(id < (*tree)->id) return findposition(id, &((*tree)->fg)); 19 return findposition(id, &((*tree)->fd)); 0 } 1 int maxdepth(node_t * ptr, int cd) { int a, b; 3 if(ptr == NULL) return cd; 4 a = maxdepth(ptr->fg, ++cd); b = maxdepth(ptr->fd, cd); 6 return MAX(a, b); 7 } 8 void freetree(node_t * ptr) { 9 node_t * tmp; 30 if(ptr == NULL) return; 31 freetree(ptr->fg); 3 tmp = ptr->fd; 33 free(ptr); freetree(tmp); 34 } 3 static int mynum = 0; 36 void treegvsub(node_t * ptr, FILE * out, int cd) { 37 if(ptr->fg) { 38 fprintf(out, "\t\"%p\" -> \"%p\";\n", ptr, ptr->fg); 39 treegvsub(ptr->fg, out, cd - 1); 40 } 41 fprintf(out, "\t\"%p\" [label=\"%d\", pos=\"%f,%f!\"];\n", ptr, ptr->id,mynum / 10.0, cd / 10.0); 4 mynum++; 43 if(ptr->fd) { 44 fprintf(out, "\t\"%p\" -> \"%p\";\n", ptr, ptr->fd); 4 treegvsub(ptr->fd, out, cd - 1); 46 } 47 } 48 void treegv(node_t * ptr, FILE * out) { 49 fprintf(out, "digraph G {\n"); 0 if(ptr) { 1 mynum = 1; treegvsub(ptr, out, maxdepth(ptr, 0)); 3 } 4 fprintf(out, "}\n"); } 6 int main(void) { 7 node_t * a = NULL; 8 srand(time(null)); 9 int i, n = 10, v; 60 for(i = 0; i < n; i++) { 61 v = n * (rand() / (RAND_MAX + 1.0)); 6 *(findposition(v, &a)) = newnode(v); 63 } 64 /* Méta-prog produisant du GraphViz */ 6 /* faire quelque chose comme: 66 gcc -Wall ab.c -o ab &&./ab > out.gv && 67 dot -Kfdp -Tps out.gv -o out.ps && pspdf out.ps 68 pour obtenir un fichier pdf contenant votre arbre 69 */ 70 treegv(a, stdout); 71 /* Libérer l arbre */ 7 freetree(a); a = NULL; 73 return 0; 74 } Figure 7 Graphes (ici arbre binaire) et méta-programmation pour l outil Graph- Viz. 4

- Voir l outil GraphViz; - Voir (sur la page web du cours) le support concernant la générationde graphes connexes (labyrinthes) et la résolution de plus courts chemins dans ces graphes.