From eb581c8a31a04eb199f081498c9e4088be59909f Mon Sep 17 00:00:00 2001 From: Felix-Vimalaratnam Date: Mon, 29 Jan 2024 17:28:51 +0100 Subject: [PATCH] =?UTF-8?q?moiti=C3=A9=20tp=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DEV1.1/CM3/calcul.c | 37 ++++++++++++++ DEV1.1/CM3/culmination1.c | 27 +++++++++++ DEV1.1/TP27/culmination.c | 24 +++++++++ DEV1.1/TP28/Makefile | 20 ++++++++ DEV1.1/TP28/chaine.c | 41 ++++++++++------ DEV1.1/TP28/chaine.h | 14 ++++++ DEV1.1/TP28/extra.c | 14 ++++++ DEV1.1/TP28/extra.h | 7 +++ DEV1.1/TP28/main.c | 40 +++++++++++++++ DEV1.1/TP28/pile | Bin 0 -> 18840 bytes DEV1.1/felix-vi_CM3.tar.gz | Bin 0 -> 827 bytes DEV2.1/Graphique/Bouton.class | Bin 0 -> 828 bytes DEV2.1/Graphique/Bouton.java | 21 ++++++++ DEV2.1/Graphique/Choix.class | Bin 0 -> 861 bytes DEV2.1/Graphique/Choix.java | 21 ++++++++ DEV2.1/Graphique/Saisie.class | Bin 0 -> 959 bytes DEV2.1/Graphique/Saisie.java | 23 +++++++++ DEV2.1/Graphique/Sirocco.class | Bin 0 -> 662 bytes DEV2.1/Graphique/Sirocco.java | 14 ++++++ DEV2.1/Mise_page/Choix.class | Bin 0 -> 965 bytes DEV2.1/Mise_page/Choix.java | 26 ++++++++++ DEV2.1/Mise_page/Damier.class | Bin 0 -> 1040 bytes DEV2.1/Mise_page/Damier.java | 23 +++++++++ DEV2.1/introduction/Bonjour.class | Bin 0 -> 417 bytes DEV2.1/introduction/Bonjour.java | 17 +++++++ DEV2.1/introduction/Grille.class | Bin 0 -> 699 bytes DEV2.1/introduction/Grille.java | 32 ++++++++++++ DEV2.1/introduction/Somme.class | Bin 0 -> 1026 bytes DEV2.1/introduction/Somme.java | 21 ++++++++ DEV2.1/introduction/Tri.class | Bin 0 -> 696 bytes DEV2.1/introduction/Tri.java | 27 +++++++++++ DEV2.1/introduction/argument.class | Bin 0 -> 955 bytes DEV2.1/introduction/argument.java | 19 ++++++++ prepa_CM3/ex1_A.c | 59 +++++++++++++++++++++++ prepa_CM3/ex1_B.c | 75 +++++++++++++++++++++++++++++ prepa_CM3/ex2_A.c | 26 ++++++++++ prepa_CM3/ex2_B.c | 31 ++++++++++++ prepa_CM3/ex3_A/makefile | 19 ++++++++ prepa_CM3/ex3_A/stack.c | 60 +++++++++++++++++++++++ prepa_CM3/ex3_A/stack.h | 22 +++++++++ prepa_CM3/ex3_A/stack_operations.c | 63 ++++++++++++++++++++++++ prepa_CM3/ex3_B/makefile | 15 ++++++ prepa_CM3/ex3_B/queu.c | 69 ++++++++++++++++++++++++++ prepa_CM3/ex3_B/queue.h | 22 +++++++++ prepa_CM3/ex3_B/text.c | 51 ++++++++++++++++++++ 45 files changed, 964 insertions(+), 16 deletions(-) create mode 100644 DEV1.1/CM3/calcul.c create mode 100644 DEV1.1/CM3/culmination1.c create mode 100644 DEV1.1/TP27/culmination.c create mode 100644 DEV1.1/TP28/Makefile create mode 100644 DEV1.1/TP28/chaine.h create mode 100644 DEV1.1/TP28/extra.c create mode 100644 DEV1.1/TP28/extra.h create mode 100644 DEV1.1/TP28/main.c create mode 100755 DEV1.1/TP28/pile create mode 100644 DEV1.1/felix-vi_CM3.tar.gz create mode 100644 DEV2.1/Graphique/Bouton.class create mode 100644 DEV2.1/Graphique/Bouton.java create mode 100644 DEV2.1/Graphique/Choix.class create mode 100644 DEV2.1/Graphique/Choix.java create mode 100644 DEV2.1/Graphique/Saisie.class create mode 100644 DEV2.1/Graphique/Saisie.java create mode 100644 DEV2.1/Graphique/Sirocco.class create mode 100644 DEV2.1/Graphique/Sirocco.java create mode 100644 DEV2.1/Mise_page/Choix.class create mode 100644 DEV2.1/Mise_page/Choix.java create mode 100644 DEV2.1/Mise_page/Damier.class create mode 100644 DEV2.1/Mise_page/Damier.java create mode 100644 DEV2.1/introduction/Bonjour.class create mode 100644 DEV2.1/introduction/Bonjour.java create mode 100644 DEV2.1/introduction/Grille.class create mode 100644 DEV2.1/introduction/Grille.java create mode 100644 DEV2.1/introduction/Somme.class create mode 100644 DEV2.1/introduction/Somme.java create mode 100644 DEV2.1/introduction/Tri.class create mode 100644 DEV2.1/introduction/Tri.java create mode 100644 DEV2.1/introduction/argument.class create mode 100644 DEV2.1/introduction/argument.java create mode 100644 prepa_CM3/ex1_A.c create mode 100644 prepa_CM3/ex1_B.c create mode 100644 prepa_CM3/ex2_A.c create mode 100644 prepa_CM3/ex2_B.c create mode 100644 prepa_CM3/ex3_A/makefile create mode 100644 prepa_CM3/ex3_A/stack.c create mode 100644 prepa_CM3/ex3_A/stack.h create mode 100644 prepa_CM3/ex3_A/stack_operations.c create mode 100644 prepa_CM3/ex3_B/makefile create mode 100644 prepa_CM3/ex3_B/queu.c create mode 100644 prepa_CM3/ex3_B/queue.h create mode 100644 prepa_CM3/ex3_B/text.c diff --git a/DEV1.1/CM3/calcul.c b/DEV1.1/CM3/calcul.c new file mode 100644 index 0000000..909a5ba --- /dev/null +++ b/DEV1.1/CM3/calcul.c @@ -0,0 +1,37 @@ +#include +#include +#include + +struct mail { + long int valeur; + struct mail* suivant; +}; +typedef struct mail maillon; + +void ajouter_fin(maillon* debut, double nouv){ + maillon* p = (maillon*) malloc(sizeof(maillon*)); + p->valeur = nouv; + maillon* fin; + fin = debut; + while(fin->suivant != NULL) + fin = fin->suivant; + fin->suivant = p; + p->suivant = NULL; + +int affichage(maillon* debut){ + if (debut->suivant == NULL){ + printf("%f",debut->valeur); + return EXIT_SUCCESS; + }else + affichage(debut->suivant); + printf("%f",debut->valeur); + return EXIT_SUCCESS; + +int main(int argc, char** argv){ + long int val1, val2; + int i; + maillon* debut1 = NULL; + maillon* debut2 = NULL; + val1 = strtol(argv[1],NULL,10); + val2 = strtol(argv[2],NULL,10); + \ No newline at end of file diff --git a/DEV1.1/CM3/culmination1.c b/DEV1.1/CM3/culmination1.c new file mode 100644 index 0000000..8335ce2 --- /dev/null +++ b/DEV1.1/CM3/culmination1.c @@ -0,0 +1,27 @@ +#include +#include +#include + +/*la variable grand lors du début du programme est la première valeur du tableau +et le tableau ne contient pas son premier élément*/ +long int superieur(long int tab[], int taille, long int grand){ + if (taille < 1) + return grand; + else if (tab[0] > grand) + grand = tab[0]; + printf("n\n"); + superieur( tab+1, taille-1, grand); +} + +int main(int argc, char** argv){ + long int val; + int i; + long int* tab= (long int*) malloc(argc*sizeof(long int)); + for (i = 1; i < argc; i++){ + val = strtol(argv[i],NULL,10); + tab[i-1] = val; + } + val = superieur( tab+1, argc-1, tab[0]); + printf("%ld\n",val); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP27/culmination.c b/DEV1.1/TP27/culmination.c new file mode 100644 index 0000000..87a42cc --- /dev/null +++ b/DEV1.1/TP27/culmination.c @@ -0,0 +1,24 @@ +#include +#include +#include + +/*la variable grand lors du début du programme est la première valeur du tableau +et le tableau ne contient pas son premier élément*/ +int superieur(long int tab[], int taille, long int grand){ + if (taille < 1) + return grand; + else if (tab[0] > grand) + grand = tab[0]; + return superieur( tab[]+1, taille-1, grand); + +int main(int argc, char** argv){ + long int val; + int i; + log int tab[argc]; + for (i = 1; i < argc; i++){ + val = strtol(argv[i]); + tab[i-1] = val; + } + val = superieur( tab[]+1, argc-1, tab[0]); + printf("%ld\n",val); + return EXIT_SUCCESS; \ No newline at end of file diff --git a/DEV1.1/TP28/Makefile b/DEV1.1/TP28/Makefile new file mode 100644 index 0000000..9792da2 --- /dev/null +++ b/DEV1.1/TP28/Makefile @@ -0,0 +1,20 @@ +but : pile + +OFILES = main.o\ + chaine.o\ + +CC = gcc + +CFLAGS = -Wall -ansi -pedantic -g + +main.o : chaine.h + +chaine.o : chaine.h + +pile : $(OFILES) + $(CC) $(CFLAGS) -o pile $(OFILES) + +clean : + -rm -f $(OFILES) pile + +.PHONY : but clean \ No newline at end of file diff --git a/DEV1.1/TP28/chaine.c b/DEV1.1/TP28/chaine.c index 1460dff..693d9e8 100644 --- a/DEV1.1/TP28/chaine.c +++ b/DEV1.1/TP28/chaine.c @@ -1,28 +1,37 @@ #include #include +#include "chaine.h" -struct maillon_s { - char valeur; - struct maillon_s* suivant; -}; -typedef struct maillon_s maillon ; - -void push(char nouv, maillon* debut){ +void push(char nouv, maillon** debut){ maillon* m = (maillon*) malloc (sizeof(maillon)); m->valeur = nouv; if (debut == NULL) m->suivant = NULL; else - m->suivant = debut; - debut = m; + m->suivant = *debut; + *debut = m; } -void pop(maillon* debut){ - maillon* m = (maillon*) malloc (sizeof(maillon)); - m->valeur = nouv; - if (debut == NULL) - m->suivant = NULL; +double pop(maillon** debut){ + maillon m = **debut; + free(*debut); + if (m.suivant == NULL) + *debut = NULL; else - m->suivant = debut; - debut = m; + *debut = m.suivant; + return m.valeur; +} + +int empty(const maillon* debut){ + return debut == NULL; +} + +double top (const maillon* debut){ + return debut->valeur; +} + +void clear (maillon** debut){ + while (empty(*debut)){ + pop(debut); + } } \ No newline at end of file diff --git a/DEV1.1/TP28/chaine.h b/DEV1.1/TP28/chaine.h new file mode 100644 index 0000000..7282b2e --- /dev/null +++ b/DEV1.1/TP28/chaine.h @@ -0,0 +1,14 @@ +#ifndef CHAINE_H +#define CHAINE_H + +struct maillon_s { + char valeur; + struct maillon_s* suivant; +}; +typedef struct maillon_s maillon ; + +void push(char nouv, maillon** debut); +double pop(maillon** debut); +int empty(const maillon* debut); + +#endif \ No newline at end of file diff --git a/DEV1.1/TP28/extra.c b/DEV1.1/TP28/extra.c new file mode 100644 index 0000000..dfc70f5 --- /dev/null +++ b/DEV1.1/TP28/extra.c @@ -0,0 +1,14 @@ +#include +#include +#include "extra.h" +#include "chaine.h" + +double top (const maillon* debut){ + return debut->valeur; +} + +void clear (maillon** debut){ + while (empty(*debut)){ + pop(debut); + } +} \ No newline at end of file diff --git a/DEV1.1/TP28/extra.h b/DEV1.1/TP28/extra.h new file mode 100644 index 0000000..eb31638 --- /dev/null +++ b/DEV1.1/TP28/extra.h @@ -0,0 +1,7 @@ +#ifndef EXTRA_H +#define EXTRA_H + +double top (const maillon* debut); +void clear (maillon** debut); + +#endif \ No newline at end of file diff --git a/DEV1.1/TP28/main.c b/DEV1.1/TP28/main.c new file mode 100644 index 0000000..9191249 --- /dev/null +++ b/DEV1.1/TP28/main.c @@ -0,0 +1,40 @@ +#include +#include +#include "chaine.h" +#include "extra.h" + +int main(void){ + char op, valeur; + maillon* debut = NULL; + printf("La pile attend vos ordres\n"); + printf("> "); + op = getchar(); + while (op != 'q'){ + if (op == '-'){ + if (empty(debut)){ + printf("La pile est vide !\n"); + printf("> "); + }else{ + valeur = pop(&debut); + printf("Le caractère %c a été supprimé\n", valeur); + printf("> "); + } + }else if (op == '+'){ + valeur = getchar(); + printf("Le caractère %c a été ajouté\n", valeur); + push(valeur, &debut); + printf("> "); + }else if (op == '/'){ + clear(&debut); + printf("La pile est vide !\n"); + printf("> "); + }else if (op == '='){ + valeur = top(debut); + printf("Le caractère le plus récent est %c\n", valeur); + printf("> "); + } + op = getchar(); + } + printf("au revoir\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP28/pile b/DEV1.1/TP28/pile new file mode 100755 index 0000000000000000000000000000000000000000..3963af24e95391a7e7b06226d8afaa53ebe0610a GIT binary patch literal 18840 zcmb<-^>JfjWMqH=W(GS35O0D2M8p9?G0cE57#J8F7%Uig85|f?7?c^<7#J8>z+w=E zFl8|M1`|XaMsq;849rk{5+DWx0|PoO162p3L2d#GfoPC@AT~B!zzz|G(F{<3fb_9~ zq@aA5IE-EiH55j}#6kMNQVJl=3=9ltvT$c-Ru0S!-d8WtZg8eLxnR3AF+0&zA2j0V{O5(<7= zk^*9*+XLgn?19lR`vRc)c0j`so%R74&cMI`qd|6ngaV(Iq=3QlyAqB#g^AFg;X z00lS$0|ShP1}lSpPG*vsiGEIsZcb)iX@zcug_*9IiC%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EAutJxKQM=Zf#EU(0|Os44}ipAR~PgXx3C;}@v^VftbF_YZ(}J~1#bXn-^!VVHgx z{S!?;Y`p#jR6n@?j7L8cs27gpe^`6g0CeaExQ&aX8C!UO1{aa^!`g=qQ2j7>!c2h% z2aL6JL_%L(Cp!z{#$hZt@U;?rrl75)5Dh~bEp!%1V2DG16==~K0|P@nJYzw0pzF8Cq5mh;6!IF@%DXFn!20nis)pEkNVQpdDt=@B_8gL3sd{ v9$@tf=*$MF60klP(Eu7R0j3_t&&C(Y&<*i3RQQlYC~Z+!SLS9IctV z{JJLZ9b4w|;|u=Yv43d1=)wOvx*Gf{zB`ILG(TAXEC2iU&-==GkLtHx{PSPrhx9-D ztq~3X*Dq*%^k^qXMT@aRiojEWweLTghprA$SrMhfF~NtaYDtsMi(k7HuFeT?3u@&k zYF@y4^G$;=hp?XJJ?kZoY>|h&^OX{6&tLn_eI;V~v1vh@Y*d?)e2TRXMO+Ww9i`MN zuzOzc(TV0f(OD09=J@%}ZeS>&y;HtqUe%^vOeEjq8|99L$3Q2T$PUu5r<_8_z4 zCn{4{>8(4ZVIkOSzw{hidft&~UHzZ)ci-o85IwtU*#oy|pMw^H2|+e{jaj<3YCFfs z%8O5Cz5GT{{jRECsPS8?;4NDHTa3*7>_yi)m3Ke7YWtQ)LhNDa%@;pjq(s_&uV1tf S7x<|EfW2h3$zlc#1_l5u^^gq! literal 0 HcmV?d00001 diff --git a/DEV2.1/Graphique/Bouton.class b/DEV2.1/Graphique/Bouton.class new file mode 100644 index 0000000000000000000000000000000000000000..e65b39949f83bd31ebaf7670892fc7aa6359cdb1 GIT binary patch literal 828 zcmX^0Z`VEs1_pBmTP_AM26=V{1uh0A26+&n2qKi&8I(B~RJa(}7*shJ)HoQ_IT$oJ z7&O@#v^W^FK`L}O7<4%p^f(ywIT#E;0*34iM(hm6j0|ixnR%Hdc8mDC~P zT*3LJMaijdnIOg7PWh!J`FVOEl{^gM3=)hCLLhd9esOtbUb?=QTTxUquh>?LKv9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-NQ zjSLJ7j10mI3=C{wK^6v11`!5PsM2%>W(H;k1_tBZ3`~*R8JK;v1sT5xGU{w&V9{pV z#=yFpfh|&qeLDk(uMYb*22O1qA?|GqJlZVV7?UR*QmZ+bTn3t{}TvC*omu?Nx z$Q7JlT9lmXmI+eK<(!e9S)m6~$ipDUAkN4j1Y%d{7nf(|rR#gS6(#1T@-P@O81XO| zGng3k*j!DHOMTyBJ5TAhcYe7_i!__%Iw;(?+HLt{4 z6JaGnkdc9_IJG1!vp5qH+Zs`tVGN24A`GGoAi%`H2#QArMg|E61_oIMMg~R(1_oBG z?F@_?85kHC86+7P7}&sqEDW3sQVh~irN0wRN^JaO`H_j1=P9&cN*lX7Oxi;I?7`GkHNwRxpzf#AMse zz#qAtLBNV#l3jNjgPgF5 z_5lY2JA)7d2ZJ~RCxapb7lRrDH-iBKC?W7NxH0fC1Tye5L@@|3Brpgvq%#OH literal 0 HcmV?d00001 diff --git a/DEV2.1/Mise_page/Choix.java b/DEV2.1/Mise_page/Choix.java new file mode 100644 index 0000000..b27d9cb --- /dev/null +++ b/DEV2.1/Mise_page/Choix.java @@ -0,0 +1,26 @@ +import javax.swing.*; +import java.awt.*; + +public class Choix { + public static void main(String[] args) { + JFrame fenetre = new JFrame(); + fenetre.setSize(500, 300); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + GridLayout gestionnaire = new GridLayout(4, 1); + fenetre.setLayout(gestionnaire); + JRadioButton etiquette = new JRadioButton("Gryffondor"); + JRadioButton etiquette1 = new JRadioButton("Serdaigle"); + JRadioButton etiquette2 = new JRadioButton("Serpantard"); + JRadioButton etiquette3 = new JRadioButton("Poufsouffle"); + ButtonGroup btn = new ButtonGroup(); + btn.add(etiquette); + btn.add(etiquette1); + btn.add(etiquette2); + btn.add(etiquette3); + fenetre.add(etiquette); + fenetre.add(etiquette1); + fenetre.add(etiquette2); + fenetre.add(etiquette3); + fenetre.setVisible(true); + } +} \ No newline at end of file diff --git a/DEV2.1/Mise_page/Damier.class b/DEV2.1/Mise_page/Damier.class new file mode 100644 index 0000000000000000000000000000000000000000..61bb22282d95e7556f69ae3e24737f3c1d4ecca5 GIT binary patch literal 1040 zcmX^0Z`VEs1_pBmM=k~-203;Hc`gPf1_dq#MFu5y24yY=Rt7l`p#maQ*%{Qh7&sZ! zK^zTs22Cyo9*{H-gBD0c8${@^Gw8B2=rJ;|*<|Krme?^eFl%UrF*2|?=clAHGVuFk z=B4_T<|d^Ug(N2Bq%tzF;WrB?0c1g_5OfAv_>E~e(W)NXy-~+Ms6U$5Vo%3_@ zi$J1=>3~8HABkgF_yy zia9YQg^@uEMJ~4>KQA?}#99;LY>@HJ`7l972Cm}NlCaF;Oh_8hh|&yWP-GBf5MlrU zCI&`OG&3+Vh%zuR$TBc8FfuSOuxf2*VBE;Sz`)2L#=yY91`%Z7WDsYNfGA}YV_;?A zWME*JxtoD0Qjp<41Z`(v_5len!@0h!dl{G_nYDu>S#*N^w3v-{FtC`h>}Ft%+|Iye z#VW}v$oNH&QD++iyCf^yHU^H}44jdoETSyi8Mv(2Bv~cdwlQ$;X5fk3&cJKM&TPgZ z$^nwiSi~SB$*wEP!CGLnje$>+Rg!%h1All62jlYp4 z!z2b#h8YZE43Z2C49W~l{~7WbIN2Gb*cq6>NScwIft4L3#KXwI@QXo-fssLmfq{XE GK^6csyWbiB literal 0 HcmV?d00001 diff --git a/DEV2.1/Mise_page/Damier.java b/DEV2.1/Mise_page/Damier.java new file mode 100644 index 0000000..03e1eb0 --- /dev/null +++ b/DEV2.1/Mise_page/Damier.java @@ -0,0 +1,23 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.Color; + +public class Damier { + public static void main(String[] args) { + Color blanc = new Color(255,255,255); + Color cyan = new Color(0,255,255); + Color tab[] = {blanc,cyan}; + int l = Integer.parseInt(args[0]); + JFrame fenetre = new JFrame(); + fenetre.setSize(500, 300); + fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + GridLayout gestionnaire = new GridLayout(l, l); + fenetre.setLayout(gestionnaire); + JTextArea block = new JTextArea(); + for (int i=0; i<(l*l); i++){ + block.setBackground(tab[i%2]); + fenetre.add(block); + } + fenetre.setVisible(true); + } +} \ No newline at end of file diff --git a/DEV2.1/introduction/Bonjour.class b/DEV2.1/introduction/Bonjour.class new file mode 100644 index 0000000000000000000000000000000000000000..adf1062100881e016ecf300408f3616ad7244b45 GIT binary patch literal 417 zcmX^0Z`VEs1_pBmSuO@P27XQk0R}-11|cp6VFnR)22pkfF-8V9o6Nk-5<5l)W)00S zMg|t={FGEi27aH+yi~u^+@#c^ki?{%R7M7t+{Da0Mg}pBXrHXavPAuy#JqI<;F6-u zymV`jMy}xe(xT*4w@i>?9;f`gto+g!YHk-`6%o00B24)S-Fh&Lz=lqmZMh1SL%)C^;(%hufqL9R-oK!{zmfXb5JVpjF zjcA{&#Ii*FoW#6z{os`Zug?hoSalW zkWL;39tK`^24x-w6$Vvy1~ncAbp{Pa21adm22CCYEe35y1}0q)!BxY^z@z{oxU?A= z*dRtQG6;YSfmrXKl$DxX!pI839_TA z;ee|FNphk}A`EC@W?cS%AIL>aU>7+t2rw`(2r#fS2r}?92r-B;2s6kr2r;NIh%#t1 zh%p#5h%;C*NH91th%Pq|~C2#H5^5Mh2GL#LPTK1~H9jpRB~PME#t^ zymbBGlA_GKbZd}C-r$nN0L<&%6>w z22l+x9`ZynKe)2EBsG_jfjPevqyeHnGhaWTC^N4lxTGjGG1r=lL6<>~k%1lTIt4~X z2Jzg)>{RFcyyV1^@XV47=ls0llEl1{VvvoVnh-OP1CfzI80=6~a~T=f3qZEye38jXV3?QkTD~J3Rpkb%*?#9{OnX{{6HMxmY7_UUsTD?V9LnA=98bFU0T4%z~h;h zms;eUlUQ7wTFl5W134_9WE?7#J7~nQgRub@tgYo3V(p z$Sz_K*AZngvSO8%WZl8Qlwi}s!npkZ%S{Z-(z_T~7#OxOu!4+b0vjs@Hh`aji9vut zj6sk=jzNGyg+Z9XfI)2s1J;{9uq|U}g|tU|?Wk5M(f7 gU|`^4U}P|0FkvuckYo^NU|`^2U}TVBU}TU40B7C*(*OVf literal 0 HcmV?d00001 diff --git a/DEV2.1/introduction/Somme.java b/DEV2.1/introduction/Somme.java new file mode 100644 index 0000000..6712d28 --- /dev/null +++ b/DEV2.1/introduction/Somme.java @@ -0,0 +1,21 @@ +/** +* Cette classe est une simple coquille pour recevoir la méthode principale +* +* @version 1.1 09 March 2014 +* @author Luc Hernandez +*/ +public class Somme { + + /** + * Affiche «Somme !» + * + * @param args la liste des arguments de la ligne de commande (inutilisée ici) + */ + public static void main(String[] args) { + int n=0; + for (String value : args){ + n = n + Integer.parseInt(value); + } + System.out.println("Somme: "+n); + } +} \ No newline at end of file diff --git a/DEV2.1/introduction/Tri.class b/DEV2.1/introduction/Tri.class new file mode 100644 index 0000000000000000000000000000000000000000..783f25f467c8408e73ec95d6dfc2865a824bc401 GIT binary patch literal 696 zcmX^0Z`VEs1_pBm9WDlT24OA+5e88%1~CS4P6i1ENiGH{25EK%8FmI)Mg}&U%)HDJ zJ4Oa(4b3n{1{UZ1lvG9rexJ;|RKL>Pq|~C2#H5^5Mh2GL#LPTK1~H9jpRB~PME#t^ zymbBGlA_GKbZd}C-r$nN0xeVnmi0z4BCtg%ppaYj0^%G9T4mMld@8i zOBfl1vABVefhpRPkwFll+B2^tH9fV6k%6Niv8XuJGp~e^K~w{a>pfwXl$K=X=sOk_ zB~}(QGO!fq7nLwFuxdnmg8YZ%jNr=RlGI#A2Il-ykdY7*GxPNWiZb&`f=h~06LYN@ z8HB+uK^10XU@rhE%E@D7VA1f@3}aAaU}Ios00AZjMo_RYFfwp4Ffhn6FfuSQFfg!c zZD(NI$iTqB$iU6Oz`zC;*56`L{4Jwy-iT|Nm5b2LrPM#}gc$S~#2Abi#2GvoBp3o1#2LaEq!{=Z z7#NfpSpG8zFtD*R@Ut@rFtRi7GcqzT{9us%$G`&;VEn-##lXlQ$iTqB#2^F!+pmjN literal 0 HcmV?d00001 diff --git a/DEV2.1/introduction/Tri.java b/DEV2.1/introduction/Tri.java new file mode 100644 index 0000000..0740ba8 --- /dev/null +++ b/DEV2.1/introduction/Tri.java @@ -0,0 +1,27 @@ +import java.util.Arrays; +/** +* Cette classe est une simple coquille pour recevoir la méthode principale +* +* @version 1.1 09 March 2014 +* @author Luc Hernandez +*/ +public class Tri { + + /** + * Affiche «Tri !» + * + * @param args la liste des arguments de la ligne de commande (inutilisée ici) + */ + public static void main(String[] args) { + int tab[] = new int[args.length]; + int i=0; + for (String value : args){ + tab[i] = Integer.parseInt(value); + i++; + } + Arrays.sort(tab); + for (int value : tab){ + System.out.println(value); + } + } +} \ No newline at end of file diff --git a/DEV2.1/introduction/argument.class b/DEV2.1/introduction/argument.class new file mode 100644 index 0000000000000000000000000000000000000000..475d75d54fadff2c9087ee7e6dbfeb7b55839168 GIT binary patch literal 955 zcmX^0Z`VEs1_pBmLoNn320=~+AqHU~1_lOkE(Qq(Np=P)b_Qui1~!|_yv!0iMh0dL z%`ip=7U%qwR7M7VpUk{eztY^K)S{5Yq?}Yn2A15!%sfU0F^y=Sti-ZJ{hY+Sbp7Cx zqRhN>Ymi3X;F84TY~REJuzGd|8Ab-K;QZ2}e`MzC2NY%Il?0a*r6%TD zb1|qhXfQHxI_2kO<(C#IFfuZT=O$*SI_KvlCzga~mSi~R=M|SE=9LsPGN@@l%s>eX zOd&=FVX$jatzu+gF92DblgG#)ip`)fb_PvQ0O&F@sDSl@t;x(Q%g;`QhCIYoZi&ey z`9+oN4El@=Y(Dw<*`)=H3_PBBd8tLtIf=!^sl|*8Gmve7ngI!GkHox`oYZ0!h(>En z=Oc-rXbh<=NX4QYITj#MW37p4gmYp}PH<*Psx>=<0V9JdhX1g+jgdhPzd8m*237_( z1`uFkU<4&G21W)>1_lOM21W)(1_lOJt?dkq8yOfF7#X-27#P^Vg6s^O4BQMnP^B>p zObo0H3=FDTKHB?ineAj{7BNU`%Nkj+Y+_)NWZA{Q%)qdXfu)6+aryseAfuSTMhP*n zFfcIiGYB#WFvv0RGpH~KG4L`lFz_-k{bOKfXW(OG{J|i@z|6qUz`(%7Ai$u*z`(%8 cz{sG*pvR!iAju%Yz`(%4z{nuVz{ns50NUF0=Kufz literal 0 HcmV?d00001 diff --git a/DEV2.1/introduction/argument.java b/DEV2.1/introduction/argument.java new file mode 100644 index 0000000..9a03e20 --- /dev/null +++ b/DEV2.1/introduction/argument.java @@ -0,0 +1,19 @@ +/** +* Cette classe est une simple coquille pour recevoir la méthode principale +* +* @version 1.1 09 March 2014 +* @author Luc Hernandez +*/ +public class argument { + + /** + * Affiche «argument !» + * + * @param args la liste des arguments de la ligne de commande (inutilisée ici) + */ + public static void main(String[] args) { + for (String value : args){ + System.out.println("Bonjour "+value); + } + } +} \ No newline at end of file diff --git a/prepa_CM3/ex1_A.c b/prepa_CM3/ex1_A.c new file mode 100644 index 0000000..e6ef9af --- /dev/null +++ b/prepa_CM3/ex1_A.c @@ -0,0 +1,59 @@ + + +#include +#include + +struct mail { + int valeur; + struct mail* suivant; +}; +typedef struct mail maillon; + + +int test(maillon* premier,int new){ + if(premier==NULL){ + return 1; + } + + if (new % premier->valeur==0) + return 0; +test(premier->suivant,new); +} + + +maillon* ajouter_debut(maillon* premier, int nouveau) { + maillon* p = (maillon*) malloc(sizeof(maillon)); + if (p) { + p->suivant = premier; + p->valeur = nouveau; + } + return p; +} + + + + +int main() { + int currentNumber, stop=1; + maillon* debut=NULL; + + while (stop) { + printf("Entrez un entier : "); + scanf("%d", ¤tNumber); + + if (currentNumber <= 0) { + printf("Fin du programme.\n"); + stop=0; + } + + + if (test(debut,currentNumber)==0) { + printf("Perdu !\n"); + stop=0; + } + debut=ajouter_debut(debut,currentNumber); + + } + + return 0; +} \ No newline at end of file diff --git a/prepa_CM3/ex1_B.c b/prepa_CM3/ex1_B.c new file mode 100644 index 0000000..60f60e1 --- /dev/null +++ b/prepa_CM3/ex1_B.c @@ -0,0 +1,75 @@ +#include +#include + +/* Définition de la structure pour un maillon de la liste chaînée*/ +struct Node { + int value; + struct Node* next; +}; + +/* Alias pour faciliter l'utilisation de la structure*/ +typedef struct Node Node; + +/* Fonction pour ajouter un entier dans la liste de manière ordonnée*/ +Node* insertOrdered(Node* head, int value) { + Node* newNode = (Node*)malloc(sizeof(Node)); + Node* current; + newNode->value = value; + newNode->next = NULL; + + if (head == NULL || value < head->value) { + newNode->next = head; + return newNode; + } + + current = head; + while (current->next != NULL && current->next->value < value) { + current = current->next; + } + + newNode->next = current->next; + current->next = newNode; + + return head; +} + +/* Fonction pour afficher les valeurs dans la liste*/ +void displayList(Node* head) { + Node* current = head; + + while (current != NULL) { + printf("%d ", current->value); + current = current->next; + } + + printf("\n"); +} + +int main() { + Node* head = NULL; /* Tête de la liste*/ + + while (1) { + int userInput; + + printf("Entrez un entier (ou appuyez sur Entrée pour quitter) : "); + if (scanf("%d", &userInput) != 1) { + /* L'utilisateur a appuyé sur Entrée, quitter la boucle*/ + break; + } + + /* Insérer l'entier dans la liste de manière ordonnée*/ + head = insertOrdered(head, userInput); + + /* Afficher la liste actuelle*/ + displayList(head); + } + + /* Libérer la mémoire allouée pour la liste à la fin du programme*/ + while (head != NULL) { + Node* temp = head; + head = head->next; + free(temp); + } + + return 0; +} \ No newline at end of file diff --git a/prepa_CM3/ex2_A.c b/prepa_CM3/ex2_A.c new file mode 100644 index 0000000..494d95d --- /dev/null +++ b/prepa_CM3/ex2_A.c @@ -0,0 +1,26 @@ +#include + +int rechercheRecursive(int valeur, int tableau[], int taille, int indice) { + if (indice == taille) { + return -1; + } + if (tableau[indice] == valeur) { + return indice; + } + return rechercheRecursive(valeur, tableau, taille, indice + 1); +} + +int main() { + int tableau[] = {5, 10, 15, 20, 25, 30, 10, 40, 50}; + int taille = sizeof(tableau) / sizeof(tableau[0]); + int resultat = rechercheRecursive(12, tableau, taille, 0); + printf("Test 1 - Valeur non présente : %d\n", resultat); + resultat = rechercheRecursive(5, tableau, taille, 0); + printf("Test 2 - Valeur présente au début : %d\n", resultat); + resultat = rechercheRecursive(50, tableau, taille, 0); + printf("Test 3 - Valeur présente à la fin : %d\n", resultat); + resultat = rechercheRecursive(10, tableau, taille, 0); + printf("Test 4 - Valeur présente duex fois : %d\n", resultat); + + return 0; +} \ No newline at end of file diff --git a/prepa_CM3/ex2_B.c b/prepa_CM3/ex2_B.c new file mode 100644 index 0000000..becbdba --- /dev/null +++ b/prepa_CM3/ex2_B.c @@ -0,0 +1,31 @@ +#include + +double recursiveSum(const double array[], int size) { + /* Cas de base : tableau de taille 1*/ + if (size == 1) { + return array[0]; + } + + /* Appel récursif : somme du premier élément et du reste du tableau*/ + return array[0] + recursiveSum(array + 1, size - 1); +} + +int main() { + /* Test 1 : tableau de 5 éléments*/ + double array1[] = {1.5, 2.5, 3.5, 4.5, 5.5}; + double array2[1] = {10.0}; + double array3[4] = {2.0, 4.0, 6.0, 8.0}; + int size1 = sizeof(array1) / sizeof(array1[0]); + int size2, size3; + printf("Somme du tableau 1 : %.2f\n", recursiveSum(array1, size1)); + + /* Test 2 : tableau de 1 élément*/ + size2 = sizeof(array2) / sizeof(array2[0]); + printf("Somme du tableau 2 : %.2f\n", recursiveSum(array2, size2)); + + /* Test 3 : tableau de 4 éléments, mais considéré de taille 3*/ + size3 = 3; + printf("Somme du tableau 3 : %.2f\n", recursiveSum(array3, size3)); + + return 0; +} diff --git a/prepa_CM3/ex3_A/makefile b/prepa_CM3/ex3_A/makefile new file mode 100644 index 0000000..2476ea8 --- /dev/null +++ b/prepa_CM3/ex3_A/makefile @@ -0,0 +1,19 @@ +but : ex3 + +OBJS = stack_operations.o\ + stack.o + +CC = gcc + +CFLAGS = -Wall -ansi -pedantic + + +stack_operations.o: stack.h + +stack.o : stack.h + +ex3: $(OBJS) + $(CC) $(CFLAGS) -o ex3 $(OBJS) + +clean: + rm -f $(OBJS) ex3 diff --git a/prepa_CM3/ex3_A/stack.c b/prepa_CM3/ex3_A/stack.c new file mode 100644 index 0000000..6321919 --- /dev/null +++ b/prepa_CM3/ex3_A/stack.c @@ -0,0 +1,60 @@ +#include +#include "stack.h" + +struct s_link { + unsigned value; + struct s_link *next; +}; + +typedef struct s_link link; + +struct s_stack { + link *first; +}; + + +/* crée une pile vide */ +stack create_stack(void) { + return (stack) calloc(1, sizeof(struct s_stack)); +} + +/* ajoute un élément à la pile. Renvoie 1 en cas de succès */ +int push(stack the_stack, unsigned the_value) { + link *new = (link*) malloc(sizeof(link)); + if (new == NULL) { + return 0; + } + new->value = the_value; + new->next = the_stack->first; + the_stack->first = new; + return 1; +} + +/* renvoie 1 si la pile est vide */ +int empty(stack the_stack) { + return the_stack->first == NULL; +} + +/* retire un élément de la pile. Renvoie l'élément retiré, ou -1 en cas d'échec */ +long pop(stack the_stack) { + if(the_stack->first == NULL) { + return -1; + } + link l = *(the_stack->first); + free(the_stack->first); + the_stack->first = l.next; + return l.value; +} + +/* détruit une pile en libérant les ressources associées */ +void destroy_stack(stack the_stack) { + link *current, *saved; + + current = the_stack->first; + while(current != NULL) { + saved = current->next; + free(current); + current = saved; + } + free(the_stack); +} \ No newline at end of file diff --git a/prepa_CM3/ex3_A/stack.h b/prepa_CM3/ex3_A/stack.h new file mode 100644 index 0000000..81897ac --- /dev/null +++ b/prepa_CM3/ex3_A/stack.h @@ -0,0 +1,22 @@ +#ifndef STACK_H +#define STACK_H + +/* le type stack représente une pile */ +typedef struct s_stack *stack; + +/* crée une pile vide. Renvoie NULL en cas d'échec */ +stack create_stack(void); + +/* ajoute un élément à la pile. Renvoie 0 en cas d'échec */ +int push(stack, unsigned); + +/* renvoie 1 si la pile est vide */ +int empty(stack); + +/* retire un élément de la pile. Renvoie l'élément retiré, ou -1 en cas d'échec */ +long pop(stack); + +/* détruit une pile en libérant les ressources associées */ +void destroy_stack(stack); + +#endif /* STACK_H */ \ No newline at end of file diff --git a/prepa_CM3/ex3_A/stack_operations.c b/prepa_CM3/ex3_A/stack_operations.c new file mode 100644 index 0000000..da15146 --- /dev/null +++ b/prepa_CM3/ex3_A/stack_operations.c @@ -0,0 +1,63 @@ +#include +#include "stack.h" + +/* Retire de la pile tous les éléments valant 0 */ +void removeZeros(stack s) { + stack tempStack = create_stack(); + + /* Transférer les éléments non nuls vers une pile temporaire*/ + while (!empty(s)) { + long value = pop(s); + if (value != 0) { + push(tempStack, value); + } + } + + /* Transférer les éléments depuis la pile temporaire vers la pile d'origine*/ + while (!empty(tempStack)) { + push(s, pop(tempStack)); + } + + /* Libérer la mémoire de la pile temporaire*/ + destroy_stack(tempStack); +} + +int main() { + stack myStack = create_stack(); + + /* Ajouter des éléments à la pile (exemple)*/ + push(myStack, 0); + push(myStack, 5); + push(myStack, 0); + push(myStack, 8); + push(myStack, 0); + push(myStack, 3); + + /* Afficher la pile avant la suppression des zéros*/ + printf("Pile avant suppression des zéros : "); + while (!empty(myStack)) { + printf("%ld ", pop(myStack)); + } + printf("\n"); + + /* Remettre des éléments à la pile (exemple)*/ + push(myStack, 0); + push(myStack, 9); + push(myStack, 0); + push(myStack, 7); + + /* Appliquer la fonction pour retirer les zéros*/ + removeZeros(myStack); + + /* Afficher la pile après la suppression des zéros*/ + printf("Pile après suppression des zéros : "); + while (!empty(myStack)) { + printf("%ld ", pop(myStack)); + } + printf("\n"); + + /* Libérer la mémoire de la pile*/ + destroy_stack(myStack); + + return 0; +} \ No newline at end of file diff --git a/prepa_CM3/ex3_B/makefile b/prepa_CM3/ex3_B/makefile new file mode 100644 index 0000000..6ec0f2a --- /dev/null +++ b/prepa_CM3/ex3_B/makefile @@ -0,0 +1,15 @@ +but: ex3 +OBJS = queu.o\ + text.o +CC = gcc +CFLAGS = -Wall -ansi -pedantic + +queu.o: queue.h + +text.o: queue.h + +ex3: $(OBJS) + $(CC) $(CFLAGS) -o ex3 $(OBJS) + +clean: + rm -f $(OBJS) ex3 diff --git a/prepa_CM3/ex3_B/queu.c b/prepa_CM3/ex3_B/queu.c new file mode 100644 index 0000000..91b95bc --- /dev/null +++ b/prepa_CM3/ex3_B/queu.c @@ -0,0 +1,69 @@ +#include +#include "queue.h" + +struct s_link { + unsigned value; + struct s_link *next; +}; + +typedef struct s_link link; + +struct s_queue { + link *first; /* sortie */ + link *last; /* entrée */ +}; + + +/* crée une file vide */ +queue create_queue(void) { + return (queue) calloc(1, sizeof(struct s_queue)); +} + +/* ajoute un élément à la file. Renvoie 1 en cas de succès */ +int enqueue(queue the_queue, unsigned the_value) { + link *new = (link*) malloc(sizeof(link)); + if (new == NULL) { + return 0; + } + new->value = the_value; + new->next = NULL; + if (the_queue->last == NULL) { + the_queue->first = new; + } else { + the_queue->last->next = new; + } + the_queue->last = new; + return 1; +} + +/* renvoie 1 si la file est vide */ +int empty(queue the_queue) { + return the_queue->first == NULL; +} + +/* retire un élément de la file. Renvoie l'élément retiré, ou -1 en cas d'échec */ +long dequeue(queue the_queue) { + if(the_queue->first == NULL) { + return -1; + } + link l = *(the_queue->first); + free(the_queue->first); + the_queue->first = l.next; + if (the_queue->first == NULL) { + the_queue->last = NULL; + } + return l.value; +} + +/* détruit une file en libérant les ressources associées */ +void destroy_queue(queue the_queue) { + link *current, *saved; + + current = the_queue->first; + while(current != NULL) { + saved = current->next; + free(current); + current = saved; + } + free(the_queue); +} \ No newline at end of file diff --git a/prepa_CM3/ex3_B/queue.h b/prepa_CM3/ex3_B/queue.h new file mode 100644 index 0000000..067bc05 --- /dev/null +++ b/prepa_CM3/ex3_B/queue.h @@ -0,0 +1,22 @@ +#ifndef QUEUE_H +#define QUEUE_H + +/* le type queue représente une file */ +typedef struct s_queue *queue; + +/* crée une file vide. Renvoie NULL en cas d'échec */ +queue create_queue(void); + +/* ajoute un élément à la file. Renvoie 0 en cas d'échec */ +int enqueue(queue, unsigned); + +/* renvoie 1 si la file est vide */ +int empty(queue); + +/* retire un élément de la file. Renvoie l'élément retiré, ou -1 en cas d'échec */ +long dequeue(queue); + +/* détruit une file en libérant les ressources associées */ +void destroy_queue(queue); + +#endif /* QUEUE_H */ \ No newline at end of file diff --git a/prepa_CM3/ex3_B/text.c b/prepa_CM3/ex3_B/text.c new file mode 100644 index 0000000..ad042f0 --- /dev/null +++ b/prepa_CM3/ex3_B/text.c @@ -0,0 +1,51 @@ +#include +#include "queue.h" + +/* Affiche les éléments de la file du plus ancien au plus récent */ +void displayQueue(queue q) { + queue tempQueue = create_queue(); /* File temporaire pour stocker les éléments*/ + int value; + + /* Afficher les éléments de la file et les stocker temporairement*/ + while (!empty(q)) { + value = dequeue(q); + printf("%d ", value); + enqueue(tempQueue, value); + } + + /* Remettre les éléments dans la file d'origine*/ + while (!empty(tempQueue)) { + enqueue(q, dequeue(tempQueue)); + } + + /* Libérer la file temporaire*/ + destroy_queue(tempQueue); + + printf("\n"); +} + +int main() { + /* Créer une file et ajouter des éléments (exemple)*/ + queue myQueue = create_queue(); + enqueue(myQueue, 14); + enqueue(myQueue, 9); + enqueue(myQueue, 28); + enqueue(myQueue, -3); + + /* Afficher les éléments de la file sans altérer la file*/ + printf("File avant affichage : "); + displayQueue(myQueue); + + /* Ajouter quelques éléments supplémentaires (exemple)*/ + enqueue(myQueue, 5); + enqueue(myQueue, 12); + + /* Afficher les éléments de la file après ajout*/ + printf("File après ajout : "); + displayQueue(myQueue); + + /* Libérer la mémoire de la file*/ + destroy_queue(myQueue); + + return 0; +} \ No newline at end of file