Browse Source

Importation du code depuis GitHub

gasc 2 years ago
commit
944682212c
100 changed files with 1261913 additions and 0 deletions
  1. 674
    0
      License
  2. BIN
      autres/monty_hall/monty_hall
  3. 106
    0
      autres/monty_hall/monty_hall.adb
  4. 4236
    0
      autres/nb_premiers/list.txt
  5. BIN
      autres/nb_premiers/nb_premiers
  6. 93
    0
      autres/nb_premiers/nb_premiers.adb
  7. 31
    0
      readme.md
  8. BIN
      semestre3/Kaprekar/main
  9. 204
    0
      semestre3/Kaprekar/main.adb
  10. BIN
      semestre3/Test_Tri/test_tri
  11. 288
    0
      semestre3/Test_Tri/test_tri.adb
  12. BIN
      semestre3/chaine_caracteres/chaine
  13. 100
    0
      semestre3/chaine_caracteres/chaine.adb
  14. 11
    0
      semestre3/piles/afficher_test.adb
  15. 1
    0
      semestre3/piles/afficher_test.ads
  16. 104
    0
      semestre3/piles/piles_entiers.adb
  17. 63
    0
      semestre3/piles/piles_entiers.ads
  18. 98
    0
      semestre3/piles/tests_piles_entiers.adb
  19. BIN
      semestre3/pointeurs/seance_1_TP+TD/pointeurs
  20. 298
    0
      semestre3/pointeurs/seance_1_TP+TD/pointeurs.adb
  21. BIN
      semestre3/pointeurs/seance_2_TP/processeur
  22. 115
    0
      semestre3/pointeurs/seance_2_TP/processeur.adb
  23. BIN
      semestre3/recursivite/binome/binome
  24. 34
    0
      semestre3/recursivite/binome/binome.adb
  25. BIN
      semestre3/recursivite/koch/koch
  26. 57
    0
      semestre3/recursivite/koch/koch.adb
  27. BIN
      semestre3/recursivite/labyrinthe/labyrinthe
  28. 65
    0
      semestre3/recursivite/labyrinthe/labyrinthe.adb
  29. BIN
      semestre3/recursivite/palindrone/palin
  30. 51
    0
      semestre3/recursivite/palindrone/palin.adb
  31. BIN
      semestre3/recursivite/somme_tableau/somme
  32. 21
    0
      semestre3/recursivite/somme_tableau/somme.adb
  33. BIN
      semestre3/recursivite/tri/recursivite
  34. 77
    0
      semestre3/recursivite/tri/recursivite.adb
  35. 11
    0
      semestre4/TP1_piles/afficher_test.adb
  36. 1
    0
      semestre4/TP1_piles/afficher_test.ads
  37. 145
    0
      semestre4/TP1_piles/piles_entiers.adb
  38. 63
    0
      semestre4/TP1_piles/piles_entiers.ads
  39. BIN
      semestre4/TP1_piles/post_fixee
  40. 134
    0
      semestre4/TP1_piles/post_fixee.adb
  41. BIN
      semestre4/TP1_piles/tests_piles_entiers
  42. 107
    0
      semestre4/TP1_piles/tests_piles_entiers.adb
  43. 11
    0
      semestre4/TP2_listes_ordonnees_type_LP/afficher_test.adb
  44. 151
    0
      semestre4/TP2_listes_ordonnees_type_LP/listes_ordonnees_entiers.adb
  45. 41
    0
      semestre4/TP2_listes_ordonnees_type_LP/listes_ordonnees_entiers.ads
  46. BIN
      semestre4/TP2_listes_ordonnees_type_LP/mon_application
  47. 39
    0
      semestre4/TP2_listes_ordonnees_type_LP/mon_application.adb
  48. BIN
      semestre4/TP2_listes_ordonnees_type_LP/test_listes_ordonnees_entiers
  49. 110
    0
      semestre4/TP2_listes_ordonnees_type_LP/test_listes_ordonnees_entiers.adb
  50. 10
    0
      semestre4/TP3_paquetages_generiques/2015-02-16_11-34-06_Annuaire_10.txt
  51. 100
    0
      semestre4/TP3_paquetages_generiques/2015-02-16_11-35-09_Annuaire_100.txt
  52. 50000
    0
      semestre4/TP3_paquetages_generiques/2015-02-16_11-35-27_Annuaire_50000.txt
  53. 11
    0
      semestre4/TP3_paquetages_generiques/afficher_test.adb
  54. 72
    0
      semestre4/TP3_paquetages_generiques/contacts.adb
  55. 51
    0
      semestre4/TP3_paquetages_generiques/contacts.ads
  56. 17
    0
      semestre4/TP3_paquetages_generiques/lire_mot.txt
  57. 4
    0
      semestre4/TP3_paquetages_generiques/listes_ordonnees_contacts.ads
  58. 180
    0
      semestre4/TP3_paquetages_generiques/listes_ordonnees_g.adb
  59. 51
    0
      semestre4/TP3_paquetages_generiques/listes_ordonnees_g.ads
  60. 9
    0
      semestre4/TP3_paquetages_generiques/pointeurs_de_strings.ads
  61. BIN
      semestre4/TP3_paquetages_generiques/tester_liste_contacts
  62. 274
    0
      semestre4/TP3_paquetages_generiques/tester_liste_contacts.adb
  63. BIN
      semestre4/TP3_paquetages_generiques/tester_liste_ordonnee_entiers
  64. 117
    0
      semestre4/TP3_paquetages_generiques/tester_liste_ordonnee_entiers.adb
  65. 11
    0
      semestre4/TP4_arbres_binaires_genericite/afficher_test.adb
  66. 1
    0
      semestre4/TP4_arbres_binaires_genericite/afficher_test.ads
  67. 226
    0
      semestre4/TP4_arbres_binaires_genericite/arbre_bin_recherche_cle_g.adb
  68. 92
    0
      semestre4/TP4_arbres_binaires_genericite/arbre_bin_recherche_cle_g.ads
  69. 102
    0
      semestre4/TP4_arbres_binaires_genericite/contact_cle.adb
  70. 46
    0
      semestre4/TP4_arbres_binaires_genericite/contact_cle.ads
  71. BIN
      semestre4/TP4_arbres_binaires_genericite/gerer_annuaire_inverse
  72. 231
    0
      semestre4/TP4_arbres_binaires_genericite/gerer_annuaire_inverse.adb
  73. 2000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A2000.txt
  74. 100
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_100.txt
  75. 100000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_100000.txt
  76. 150000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_150000.txt
  77. 50000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_50000.txt
  78. 100
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_100.txt
  79. 100000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_100000.txt
  80. 150000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_150000.txt
  81. 50000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_50000.txt
  82. 10
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/T_10.txt
  83. 12
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/perf.sh
  84. 100
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_100.txt.perf
  85. 100000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_100000.txt.perf
  86. 150000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_150000.txt.perf
  87. 50000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_50000.txt.perf
  88. 100
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_100.txt.perf
  89. 100000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_100000.txt.perf
  90. 150000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_150000.txt.perf
  91. 50000
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_50000.txt.perf
  92. 10
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/T_10.txt.perf
  93. 11
    0
      semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/perf.sh.perf
  94. 184
    0
      semestre4/TP4_arbres_binaires_genericite/liste_ordonnee_cle_g.adb
  95. 53
    0
      semestre4/TP4_arbres_binaires_genericite/liste_ordonnee_cle_g.ads
  96. 14
    0
      semestre4/TP4_arbres_binaires_genericite/output_example.txt
  97. 9
    0
      semestre4/TP4_arbres_binaires_genericite/pointeurs_de_strings.ads
  98. BIN
      semestre4/TP4_arbres_binaires_genericite/tester_abr_contacts
  99. 65
    0
      semestre4/TP4_arbres_binaires_genericite/tester_abr_contacts.adb
  100. 0
    0
      semestre4/TP4_arbres_binaires_genericite/tester_abr_entiers

+ 674
- 0
License View File

@@ -0,0 +1,674 @@
1
+                    GNU GENERAL PUBLIC LICENSE
2
+                       Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+                            Preamble
9
+
10
+  The GNU General Public License is a free, copyleft license for
11
+software and other kinds of works.
12
+
13
+  The licenses for most software and other practical works are designed
14
+to take away your freedom to share and change the works.  By contrast,
15
+the GNU General Public License is intended to guarantee your freedom to
16
+share and change all versions of a program--to make sure it remains free
17
+software for all its users.  We, the Free Software Foundation, use the
18
+GNU General Public License for most of our software; it applies also to
19
+any other work released this way by its authors.  You can apply it to
20
+your programs, too.
21
+
22
+  When we speak of free software, we are referring to freedom, not
23
+price.  Our General Public Licenses are designed to make sure that you
24
+have the freedom to distribute copies of free software (and charge for
25
+them if you wish), that you receive source code or can get it if you
26
+want it, that you can change the software or use pieces of it in new
27
+free programs, and that you know you can do these things.
28
+
29
+  To protect your rights, we need to prevent others from denying you
30
+these rights or asking you to surrender the rights.  Therefore, you have
31
+certain responsibilities if you distribute copies of the software, or if
32
+you modify it: responsibilities to respect the freedom of others.
33
+
34
+  For example, if you distribute copies of such a program, whether
35
+gratis or for a fee, you must pass on to the recipients the same
36
+freedoms that you received.  You must make sure that they, too, receive
37
+or can get the source code.  And you must show them these terms so they
38
+know their rights.
39
+
40
+  Developers that use the GNU GPL protect your rights with two steps:
41
+(1) assert copyright on the software, and (2) offer you this License
42
+giving you legal permission to copy, distribute and/or modify it.
43
+
44
+  For the developers' and authors' protection, the GPL clearly explains
45
+that there is no warranty for this free software.  For both users' and
46
+authors' sake, the GPL requires that modified versions be marked as
47
+changed, so that their problems will not be attributed erroneously to
48
+authors of previous versions.
49
+
50
+  Some devices are designed to deny users access to install or run
51
+modified versions of the software inside them, although the manufacturer
52
+can do so.  This is fundamentally incompatible with the aim of
53
+protecting users' freedom to change the software.  The systematic
54
+pattern of such abuse occurs in the area of products for individuals to
55
+use, which is precisely where it is most unacceptable.  Therefore, we
56
+have designed this version of the GPL to prohibit the practice for those
57
+products.  If such problems arise substantially in other domains, we
58
+stand ready to extend this provision to those domains in future versions
59
+of the GPL, as needed to protect the freedom of users.
60
+
61
+  Finally, every program is threatened constantly by software patents.
62
+States should not allow patents to restrict development and use of
63
+software on general-purpose computers, but in those that do, we wish to
64
+avoid the special danger that patents applied to a free program could
65
+make it effectively proprietary.  To prevent this, the GPL assures that
66
+patents cannot be used to render the program non-free.
67
+
68
+  The precise terms and conditions for copying, distribution and
69
+modification follow.
70
+
71
+                       TERMS AND CONDITIONS
72
+
73
+  0. Definitions.
74
+
75
+  "This License" refers to version 3 of the GNU General Public License.
76
+
77
+  "Copyright" also means copyright-like laws that apply to other kinds of
78
+works, such as semiconductor masks.
79
+
80
+  "The Program" refers to any copyrightable work licensed under this
81
+License.  Each licensee is addressed as "you".  "Licensees" and
82
+"recipients" may be individuals or organizations.
83
+
84
+  To "modify" a work means to copy from or adapt all or part of the work
85
+in a fashion requiring copyright permission, other than the making of an
86
+exact copy.  The resulting work is called a "modified version" of the
87
+earlier work or a work "based on" the earlier work.
88
+
89
+  A "covered work" means either the unmodified Program or a work based
90
+on the Program.
91
+
92
+  To "propagate" a work means to do anything with it that, without
93
+permission, would make you directly or secondarily liable for
94
+infringement under applicable copyright law, except executing it on a
95
+computer or modifying a private copy.  Propagation includes copying,
96
+distribution (with or without modification), making available to the
97
+public, and in some countries other activities as well.
98
+
99
+  To "convey" a work means any kind of propagation that enables other
100
+parties to make or receive copies.  Mere interaction with a user through
101
+a computer network, with no transfer of a copy, is not conveying.
102
+
103
+  An interactive user interface displays "Appropriate Legal Notices"
104
+to the extent that it includes a convenient and prominently visible
105
+feature that (1) displays an appropriate copyright notice, and (2)
106
+tells the user that there is no warranty for the work (except to the
107
+extent that warranties are provided), that licensees may convey the
108
+work under this License, and how to view a copy of this License.  If
109
+the interface presents a list of user commands or options, such as a
110
+menu, a prominent item in the list meets this criterion.
111
+
112
+  1. Source Code.
113
+
114
+  The "source code" for a work means the preferred form of the work
115
+for making modifications to it.  "Object code" means any non-source
116
+form of a work.
117
+
118
+  A "Standard Interface" means an interface that either is an official
119
+standard defined by a recognized standards body, or, in the case of
120
+interfaces specified for a particular programming language, one that
121
+is widely used among developers working in that language.
122
+
123
+  The "System Libraries" of an executable work include anything, other
124
+than the work as a whole, that (a) is included in the normal form of
125
+packaging a Major Component, but which is not part of that Major
126
+Component, and (b) serves only to enable use of the work with that
127
+Major Component, or to implement a Standard Interface for which an
128
+implementation is available to the public in source code form.  A
129
+"Major Component", in this context, means a major essential component
130
+(kernel, window system, and so on) of the specific operating system
131
+(if any) on which the executable work runs, or a compiler used to
132
+produce the work, or an object code interpreter used to run it.
133
+
134
+  The "Corresponding Source" for a work in object code form means all
135
+the source code needed to generate, install, and (for an executable
136
+work) run the object code and to modify the work, including scripts to
137
+control those activities.  However, it does not include the work's
138
+System Libraries, or general-purpose tools or generally available free
139
+programs which are used unmodified in performing those activities but
140
+which are not part of the work.  For example, Corresponding Source
141
+includes interface definition files associated with source files for
142
+the work, and the source code for shared libraries and dynamically
143
+linked subprograms that the work is specifically designed to require,
144
+such as by intimate data communication or control flow between those
145
+subprograms and other parts of the work.
146
+
147
+  The Corresponding Source need not include anything that users
148
+can regenerate automatically from other parts of the Corresponding
149
+Source.
150
+
151
+  The Corresponding Source for a work in source code form is that
152
+same work.
153
+
154
+  2. Basic Permissions.
155
+
156
+  All rights granted under this License are granted for the term of
157
+copyright on the Program, and are irrevocable provided the stated
158
+conditions are met.  This License explicitly affirms your unlimited
159
+permission to run the unmodified Program.  The output from running a
160
+covered work is covered by this License only if the output, given its
161
+content, constitutes a covered work.  This License acknowledges your
162
+rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+  You may make, run and propagate covered works that you do not
165
+convey, without conditions so long as your license otherwise remains
166
+in force.  You may convey covered works to others for the sole purpose
167
+of having them make modifications exclusively for you, or provide you
168
+with facilities for running those works, provided that you comply with
169
+the terms of this License in conveying all material for which you do
170
+not control copyright.  Those thus making or running the covered works
171
+for you must do so exclusively on your behalf, under your direction
172
+and control, on terms that prohibit them from making any copies of
173
+your copyrighted material outside their relationship with you.
174
+
175
+  Conveying under any other circumstances is permitted solely under
176
+the conditions stated below.  Sublicensing is not allowed; section 10
177
+makes it unnecessary.
178
+
179
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+  No covered work shall be deemed part of an effective technological
182
+measure under any applicable law fulfilling obligations under article
183
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+similar laws prohibiting or restricting circumvention of such
185
+measures.
186
+
187
+  When you convey a covered work, you waive any legal power to forbid
188
+circumvention of technological measures to the extent such circumvention
189
+is effected by exercising rights under this License with respect to
190
+the covered work, and you disclaim any intention to limit operation or
191
+modification of the work as a means of enforcing, against the work's
192
+users, your or third parties' legal rights to forbid circumvention of
193
+technological measures.
194
+
195
+  4. Conveying Verbatim Copies.
196
+
197
+  You may convey verbatim copies of the Program's source code as you
198
+receive it, in any medium, provided that you conspicuously and
199
+appropriately publish on each copy an appropriate copyright notice;
200
+keep intact all notices stating that this License and any
201
+non-permissive terms added in accord with section 7 apply to the code;
202
+keep intact all notices of the absence of any warranty; and give all
203
+recipients a copy of this License along with the Program.
204
+
205
+  You may charge any price or no price for each copy that you convey,
206
+and you may offer support or warranty protection for a fee.
207
+
208
+  5. Conveying Modified Source Versions.
209
+
210
+  You may convey a work based on the Program, or the modifications to
211
+produce it from the Program, in the form of source code under the
212
+terms of section 4, provided that you also meet all of these conditions:
213
+
214
+    a) The work must carry prominent notices stating that you modified
215
+    it, and giving a relevant date.
216
+
217
+    b) The work must carry prominent notices stating that it is
218
+    released under this License and any conditions added under section
219
+    7.  This requirement modifies the requirement in section 4 to
220
+    "keep intact all notices".
221
+
222
+    c) You must license the entire work, as a whole, under this
223
+    License to anyone who comes into possession of a copy.  This
224
+    License will therefore apply, along with any applicable section 7
225
+    additional terms, to the whole of the work, and all its parts,
226
+    regardless of how they are packaged.  This License gives no
227
+    permission to license the work in any other way, but it does not
228
+    invalidate such permission if you have separately received it.
229
+
230
+    d) If the work has interactive user interfaces, each must display
231
+    Appropriate Legal Notices; however, if the Program has interactive
232
+    interfaces that do not display Appropriate Legal Notices, your
233
+    work need not make them do so.
234
+
235
+  A compilation of a covered work with other separate and independent
236
+works, which are not by their nature extensions of the covered work,
237
+and which are not combined with it such as to form a larger program,
238
+in or on a volume of a storage or distribution medium, is called an
239
+"aggregate" if the compilation and its resulting copyright are not
240
+used to limit the access or legal rights of the compilation's users
241
+beyond what the individual works permit.  Inclusion of a covered work
242
+in an aggregate does not cause this License to apply to the other
243
+parts of the aggregate.
244
+
245
+  6. Conveying Non-Source Forms.
246
+
247
+  You may convey a covered work in object code form under the terms
248
+of sections 4 and 5, provided that you also convey the
249
+machine-readable Corresponding Source under the terms of this License,
250
+in one of these ways:
251
+
252
+    a) Convey the object code in, or embodied in, a physical product
253
+    (including a physical distribution medium), accompanied by the
254
+    Corresponding Source fixed on a durable physical medium
255
+    customarily used for software interchange.
256
+
257
+    b) Convey the object code in, or embodied in, a physical product
258
+    (including a physical distribution medium), accompanied by a
259
+    written offer, valid for at least three years and valid for as
260
+    long as you offer spare parts or customer support for that product
261
+    model, to give anyone who possesses the object code either (1) a
262
+    copy of the Corresponding Source for all the software in the
263
+    product that is covered by this License, on a durable physical
264
+    medium customarily used for software interchange, for a price no
265
+    more than your reasonable cost of physically performing this
266
+    conveying of source, or (2) access to copy the
267
+    Corresponding Source from a network server at no charge.
268
+
269
+    c) Convey individual copies of the object code with a copy of the
270
+    written offer to provide the Corresponding Source.  This
271
+    alternative is allowed only occasionally and noncommercially, and
272
+    only if you received the object code with such an offer, in accord
273
+    with subsection 6b.
274
+
275
+    d) Convey the object code by offering access from a designated
276
+    place (gratis or for a charge), and offer equivalent access to the
277
+    Corresponding Source in the same way through the same place at no
278
+    further charge.  You need not require recipients to copy the
279
+    Corresponding Source along with the object code.  If the place to
280
+    copy the object code is a network server, the Corresponding Source
281
+    may be on a different server (operated by you or a third party)
282
+    that supports equivalent copying facilities, provided you maintain
283
+    clear directions next to the object code saying where to find the
284
+    Corresponding Source.  Regardless of what server hosts the
285
+    Corresponding Source, you remain obligated to ensure that it is
286
+    available for as long as needed to satisfy these requirements.
287
+
288
+    e) Convey the object code using peer-to-peer transmission, provided
289
+    you inform other peers where the object code and Corresponding
290
+    Source of the work are being offered to the general public at no
291
+    charge under subsection 6d.
292
+
293
+  A separable portion of the object code, whose source code is excluded
294
+from the Corresponding Source as a System Library, need not be
295
+included in conveying the object code work.
296
+
297
+  A "User Product" is either (1) a "consumer product", which means any
298
+tangible personal property which is normally used for personal, family,
299
+or household purposes, or (2) anything designed or sold for incorporation
300
+into a dwelling.  In determining whether a product is a consumer product,
301
+doubtful cases shall be resolved in favor of coverage.  For a particular
302
+product received by a particular user, "normally used" refers to a
303
+typical or common use of that class of product, regardless of the status
304
+of the particular user or of the way in which the particular user
305
+actually uses, or expects or is expected to use, the product.  A product
306
+is a consumer product regardless of whether the product has substantial
307
+commercial, industrial or non-consumer uses, unless such uses represent
308
+the only significant mode of use of the product.
309
+
310
+  "Installation Information" for a User Product means any methods,
311
+procedures, authorization keys, or other information required to install
312
+and execute modified versions of a covered work in that User Product from
313
+a modified version of its Corresponding Source.  The information must
314
+suffice to ensure that the continued functioning of the modified object
315
+code is in no case prevented or interfered with solely because
316
+modification has been made.
317
+
318
+  If you convey an object code work under this section in, or with, or
319
+specifically for use in, a User Product, and the conveying occurs as
320
+part of a transaction in which the right of possession and use of the
321
+User Product is transferred to the recipient in perpetuity or for a
322
+fixed term (regardless of how the transaction is characterized), the
323
+Corresponding Source conveyed under this section must be accompanied
324
+by the Installation Information.  But this requirement does not apply
325
+if neither you nor any third party retains the ability to install
326
+modified object code on the User Product (for example, the work has
327
+been installed in ROM).
328
+
329
+  The requirement to provide Installation Information does not include a
330
+requirement to continue to provide support service, warranty, or updates
331
+for a work that has been modified or installed by the recipient, or for
332
+the User Product in which it has been modified or installed.  Access to a
333
+network may be denied when the modification itself materially and
334
+adversely affects the operation of the network or violates the rules and
335
+protocols for communication across the network.
336
+
337
+  Corresponding Source conveyed, and Installation Information provided,
338
+in accord with this section must be in a format that is publicly
339
+documented (and with an implementation available to the public in
340
+source code form), and must require no special password or key for
341
+unpacking, reading or copying.
342
+
343
+  7. Additional Terms.
344
+
345
+  "Additional permissions" are terms that supplement the terms of this
346
+License by making exceptions from one or more of its conditions.
347
+Additional permissions that are applicable to the entire Program shall
348
+be treated as though they were included in this License, to the extent
349
+that they are valid under applicable law.  If additional permissions
350
+apply only to part of the Program, that part may be used separately
351
+under those permissions, but the entire Program remains governed by
352
+this License without regard to the additional permissions.
353
+
354
+  When you convey a copy of a covered work, you may at your option
355
+remove any additional permissions from that copy, or from any part of
356
+it.  (Additional permissions may be written to require their own
357
+removal in certain cases when you modify the work.)  You may place
358
+additional permissions on material, added by you to a covered work,
359
+for which you have or can give appropriate copyright permission.
360
+
361
+  Notwithstanding any other provision of this License, for material you
362
+add to a covered work, you may (if authorized by the copyright holders of
363
+that material) supplement the terms of this License with terms:
364
+
365
+    a) Disclaiming warranty or limiting liability differently from the
366
+    terms of sections 15 and 16 of this License; or
367
+
368
+    b) Requiring preservation of specified reasonable legal notices or
369
+    author attributions in that material or in the Appropriate Legal
370
+    Notices displayed by works containing it; or
371
+
372
+    c) Prohibiting misrepresentation of the origin of that material, or
373
+    requiring that modified versions of such material be marked in
374
+    reasonable ways as different from the original version; or
375
+
376
+    d) Limiting the use for publicity purposes of names of licensors or
377
+    authors of the material; or
378
+
379
+    e) Declining to grant rights under trademark law for use of some
380
+    trade names, trademarks, or service marks; or
381
+
382
+    f) Requiring indemnification of licensors and authors of that
383
+    material by anyone who conveys the material (or modified versions of
384
+    it) with contractual assumptions of liability to the recipient, for
385
+    any liability that these contractual assumptions directly impose on
386
+    those licensors and authors.
387
+
388
+  All other non-permissive additional terms are considered "further
389
+restrictions" within the meaning of section 10.  If the Program as you
390
+received it, or any part of it, contains a notice stating that it is
391
+governed by this License along with a term that is a further
392
+restriction, you may remove that term.  If a license document contains
393
+a further restriction but permits relicensing or conveying under this
394
+License, you may add to a covered work material governed by the terms
395
+of that license document, provided that the further restriction does
396
+not survive such relicensing or conveying.
397
+
398
+  If you add terms to a covered work in accord with this section, you
399
+must place, in the relevant source files, a statement of the
400
+additional terms that apply to those files, or a notice indicating
401
+where to find the applicable terms.
402
+
403
+  Additional terms, permissive or non-permissive, may be stated in the
404
+form of a separately written license, or stated as exceptions;
405
+the above requirements apply either way.
406
+
407
+  8. Termination.
408
+
409
+  You may not propagate or modify a covered work except as expressly
410
+provided under this License.  Any attempt otherwise to propagate or
411
+modify it is void, and will automatically terminate your rights under
412
+this License (including any patent licenses granted under the third
413
+paragraph of section 11).
414
+
415
+  However, if you cease all violation of this License, then your
416
+license from a particular copyright holder is reinstated (a)
417
+provisionally, unless and until the copyright holder explicitly and
418
+finally terminates your license, and (b) permanently, if the copyright
419
+holder fails to notify you of the violation by some reasonable means
420
+prior to 60 days after the cessation.
421
+
422
+  Moreover, your license from a particular copyright holder is
423
+reinstated permanently if the copyright holder notifies you of the
424
+violation by some reasonable means, this is the first time you have
425
+received notice of violation of this License (for any work) from that
426
+copyright holder, and you cure the violation prior to 30 days after
427
+your receipt of the notice.
428
+
429
+  Termination of your rights under this section does not terminate the
430
+licenses of parties who have received copies or rights from you under
431
+this License.  If your rights have been terminated and not permanently
432
+reinstated, you do not qualify to receive new licenses for the same
433
+material under section 10.
434
+
435
+  9. Acceptance Not Required for Having Copies.
436
+
437
+  You are not required to accept this License in order to receive or
438
+run a copy of the Program.  Ancillary propagation of a covered work
439
+occurring solely as a consequence of using peer-to-peer transmission
440
+to receive a copy likewise does not require acceptance.  However,
441
+nothing other than this License grants you permission to propagate or
442
+modify any covered work.  These actions infringe copyright if you do
443
+not accept this License.  Therefore, by modifying or propagating a
444
+covered work, you indicate your acceptance of this License to do so.
445
+
446
+  10. Automatic Licensing of Downstream Recipients.
447
+
448
+  Each time you convey a covered work, the recipient automatically
449
+receives a license from the original licensors, to run, modify and
450
+propagate that work, subject to this License.  You are not responsible
451
+for enforcing compliance by third parties with this License.
452
+
453
+  An "entity transaction" is a transaction transferring control of an
454
+organization, or substantially all assets of one, or subdividing an
455
+organization, or merging organizations.  If propagation of a covered
456
+work results from an entity transaction, each party to that
457
+transaction who receives a copy of the work also receives whatever
458
+licenses to the work the party's predecessor in interest had or could
459
+give under the previous paragraph, plus a right to possession of the
460
+Corresponding Source of the work from the predecessor in interest, if
461
+the predecessor has it or can get it with reasonable efforts.
462
+
463
+  You may not impose any further restrictions on the exercise of the
464
+rights granted or affirmed under this License.  For example, you may
465
+not impose a license fee, royalty, or other charge for exercise of
466
+rights granted under this License, and you may not initiate litigation
467
+(including a cross-claim or counterclaim in a lawsuit) alleging that
468
+any patent claim is infringed by making, using, selling, offering for
469
+sale, or importing the Program or any portion of it.
470
+
471
+  11. Patents.
472
+
473
+  A "contributor" is a copyright holder who authorizes use under this
474
+License of the Program or a work on which the Program is based.  The
475
+work thus licensed is called the contributor's "contributor version".
476
+
477
+  A contributor's "essential patent claims" are all patent claims
478
+owned or controlled by the contributor, whether already acquired or
479
+hereafter acquired, that would be infringed by some manner, permitted
480
+by this License, of making, using, or selling its contributor version,
481
+but do not include claims that would be infringed only as a
482
+consequence of further modification of the contributor version.  For
483
+purposes of this definition, "control" includes the right to grant
484
+patent sublicenses in a manner consistent with the requirements of
485
+this License.
486
+
487
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+patent license under the contributor's essential patent claims, to
489
+make, use, sell, offer for sale, import and otherwise run, modify and
490
+propagate the contents of its contributor version.
491
+
492
+  In the following three paragraphs, a "patent license" is any express
493
+agreement or commitment, however denominated, not to enforce a patent
494
+(such as an express permission to practice a patent or covenant not to
495
+sue for patent infringement).  To "grant" such a patent license to a
496
+party means to make such an agreement or commitment not to enforce a
497
+patent against the party.
498
+
499
+  If you convey a covered work, knowingly relying on a patent license,
500
+and the Corresponding Source of the work is not available for anyone
501
+to copy, free of charge and under the terms of this License, through a
502
+publicly available network server or other readily accessible means,
503
+then you must either (1) cause the Corresponding Source to be so
504
+available, or (2) arrange to deprive yourself of the benefit of the
505
+patent license for this particular work, or (3) arrange, in a manner
506
+consistent with the requirements of this License, to extend the patent
507
+license to downstream recipients.  "Knowingly relying" means you have
508
+actual knowledge that, but for the patent license, your conveying the
509
+covered work in a country, or your recipient's use of the covered work
510
+in a country, would infringe one or more identifiable patents in that
511
+country that you have reason to believe are valid.
512
+
513
+  If, pursuant to or in connection with a single transaction or
514
+arrangement, you convey, or propagate by procuring conveyance of, a
515
+covered work, and grant a patent license to some of the parties
516
+receiving the covered work authorizing them to use, propagate, modify
517
+or convey a specific copy of the covered work, then the patent license
518
+you grant is automatically extended to all recipients of the covered
519
+work and works based on it.
520
+
521
+  A patent license is "discriminatory" if it does not include within
522
+the scope of its coverage, prohibits the exercise of, or is
523
+conditioned on the non-exercise of one or more of the rights that are
524
+specifically granted under this License.  You may not convey a covered
525
+work if you are a party to an arrangement with a third party that is
526
+in the business of distributing software, under which you make payment
527
+to the third party based on the extent of your activity of conveying
528
+the work, and under which the third party grants, to any of the
529
+parties who would receive the covered work from you, a discriminatory
530
+patent license (a) in connection with copies of the covered work
531
+conveyed by you (or copies made from those copies), or (b) primarily
532
+for and in connection with specific products or compilations that
533
+contain the covered work, unless you entered into that arrangement,
534
+or that patent license was granted, prior to 28 March 2007.
535
+
536
+  Nothing in this License shall be construed as excluding or limiting
537
+any implied license or other defenses to infringement that may
538
+otherwise be available to you under applicable patent law.
539
+
540
+  12. No Surrender of Others' Freedom.
541
+
542
+  If conditions are imposed on you (whether by court order, agreement or
543
+otherwise) that contradict the conditions of this License, they do not
544
+excuse you from the conditions of this License.  If you cannot convey a
545
+covered work so as to satisfy simultaneously your obligations under this
546
+License and any other pertinent obligations, then as a consequence you may
547
+not convey it at all.  For example, if you agree to terms that obligate you
548
+to collect a royalty for further conveying from those to whom you convey
549
+the Program, the only way you could satisfy both those terms and this
550
+License would be to refrain entirely from conveying the Program.
551
+
552
+  13. Use with the GNU Affero General Public License.
553
+
554
+  Notwithstanding any other provision of this License, you have
555
+permission to link or combine any covered work with a work licensed
556
+under version 3 of the GNU Affero General Public License into a single
557
+combined work, and to convey the resulting work.  The terms of this
558
+License will continue to apply to the part which is the covered work,
559
+but the special requirements of the GNU Affero General Public License,
560
+section 13, concerning interaction through a network will apply to the
561
+combination as such.
562
+
563
+  14. Revised Versions of this License.
564
+
565
+  The Free Software Foundation may publish revised and/or new versions of
566
+the GNU General Public License from time to time.  Such new versions will
567
+be similar in spirit to the present version, but may differ in detail to
568
+address new problems or concerns.
569
+
570
+  Each version is given a distinguishing version number.  If the
571
+Program specifies that a certain numbered version of the GNU General
572
+Public License "or any later version" applies to it, you have the
573
+option of following the terms and conditions either of that numbered
574
+version or of any later version published by the Free Software
575
+Foundation.  If the Program does not specify a version number of the
576
+GNU General Public License, you may choose any version ever published
577
+by the Free Software Foundation.
578
+
579
+  If the Program specifies that a proxy can decide which future
580
+versions of the GNU General Public License can be used, that proxy's
581
+public statement of acceptance of a version permanently authorizes you
582
+to choose that version for the Program.
583
+
584
+  Later license versions may give you additional or different
585
+permissions.  However, no additional obligations are imposed on any
586
+author or copyright holder as a result of your choosing to follow a
587
+later version.
588
+
589
+  15. Disclaimer of Warranty.
590
+
591
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+  16. Limitation of Liability.
601
+
602
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+SUCH DAMAGES.
611
+
612
+  17. Interpretation of Sections 15 and 16.
613
+
614
+  If the disclaimer of warranty and limitation of liability provided
615
+above cannot be given local legal effect according to their terms,
616
+reviewing courts shall apply local law that most closely approximates
617
+an absolute waiver of all civil liability in connection with the
618
+Program, unless a warranty or assumption of liability accompanies a
619
+copy of the Program in return for a fee.
620
+
621
+                     END OF TERMS AND CONDITIONS
622
+
623
+            How to Apply These Terms to Your New Programs
624
+
625
+  If you develop a new program, and you want it to be of the greatest
626
+possible use to the public, the best way to achieve this is to make it
627
+free software which everyone can redistribute and change under these terms.
628
+
629
+  To do so, attach the following notices to the program.  It is safest
630
+to attach them to the start of each source file to most effectively
631
+state the exclusion of warranty; and each file should have at least
632
+the "copyright" line and a pointer to where the full notice is found.
633
+
634
+    <one line to give the program's name and a brief idea of what it does.>
635
+    Copyright (C) <year>  <name of author>
636
+
637
+    This program is free software: you can redistribute it and/or modify
638
+    it under the terms of the GNU General Public License as published by
639
+    the Free Software Foundation, either version 3 of the License, or
640
+    (at your option) any later version.
641
+
642
+    This program is distributed in the hope that it will be useful,
643
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
645
+    GNU General Public License for more details.
646
+
647
+    You should have received a copy of the GNU General Public License
648
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
649
+
650
+Also add information on how to contact you by electronic and paper mail.
651
+
652
+  If the program does terminal interaction, make it output a short
653
+notice like this when it starts in an interactive mode:
654
+
655
+    <program>  Copyright (C) <year>  <name of author>
656
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+    This is free software, and you are welcome to redistribute it
658
+    under certain conditions; type `show c' for details.
659
+
660
+The hypothetical commands `show w' and `show c' should show the appropriate
661
+parts of the General Public License.  Of course, your program's commands
662
+might be different; for a GUI interface, you would use an "about box".
663
+
664
+  You should also get your employer (if you work as a programmer) or school,
665
+if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+For more information on this, and how to apply and follow the GNU GPL, see
667
+<https://www.gnu.org/licenses/>.
668
+
669
+  The GNU General Public License does not permit incorporating your program
670
+into proprietary programs.  If your program is a subroutine library, you
671
+may consider it more useful to permit linking proprietary applications with
672
+the library.  If this is what you want to do, use the GNU Lesser General
673
+Public License instead of this License.  But first, please read
674
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

BIN
autres/monty_hall/monty_hall View File


+ 106
- 0
autres/monty_hall/monty_hall.adb View File

@@ -0,0 +1,106 @@
1
+with Ada.Text_Io;
2
+with Ada.Numerics.Discrete_Random;
3
+with Ada.Command_Line;
4
+
5
+use Ada.Command_Line;
6
+use Ada.Text_Io;
7
+
8
+procedure Monty_Hall is 
9
+   
10
+   subtype Ternary is Integer range 1..3;
11
+   
12
+   package Random_bool is new Ada.Numerics.Discrete_Random(Boolean);
13
+   package Random_Ternary is new Ada.Numerics.Discrete_Random(Ternary);
14
+   
15
+   package RB renames Random_Bool;
16
+   package RT renames Random_Ternary;
17
+   
18
+   HasardRB : RB.Generator;
19
+   HasardRT : RT.Generator;
20
+   
21
+   
22
+   type Door is record
23
+      Name : String;
24
+      Is_Open : Boolean;
25
+      Hide_Goat : Boolean;
26
+   end record;
27
+   
28
+   type List_D is array (Integer range <>) of Door;
29
+   
30
+   type Strat is (C,N,R); -- Change / Not_Change / Random
31
+   
32
+   --Initialisation des portes
33
+   procedure Set_Door (A,B,C : out Door) is
34
+      T : Ternary;
35
+   begin
36
+      A := ("A",False, False);
37
+      B := ("B",False, False);
38
+      C := ("C",False, False);
39
+      
40
+      T := RT.Random(HasardRT);
41
+      case T is
42
+	 when 1 => A.Hide_Goat := True;
43
+	 when 2 => B.Hide_Goat := True;
44
+	 when 3 => C.Hide_Goat := True;
45
+      end case;
46
+   end Set_Door;
47
+   
48
+   -- Le présentateur désigne une porte dans la liste
49
+   function Presentateur(L : in List_D(1..2)) return Integer is
50
+      I : Integer;
51
+   begin
52
+      if List_D(1).Hide_Goat and List_D(2).Hide_Goat then
53
+	 I := RB.Random(HasardRB);
54
+      elsif List_D(1).Hide_Goat and not List_D(2).Hide_Goat then
55
+	 I := 1;
56
+      else
57
+	 I := 2;
58
+      end if;
59
+      return I;
60
+   end Presentateur;
61
+   
62
+   
63
+   --Joue 1 jeu, retourne vrai si le joueur gagne
64
+   function Game (S : in Strat) return Boolean is
65
+      A, B, C, M : Door; -- M buffer
66
+      Choice_T1 : Door;
67
+      L1 : List_D(1..3) := (A,B,C);
68
+      L2 : List-D(1..2); 
69
+   begin
70
+      Set_Door(A,B,C);
71
+      
72
+      -- Tour 1 et liste des porte restantes
73
+      case RT.Random(HasardRT) is
74
+	 when 1 => Choice_T1 := A; L2 := (B,C); M := A;
75
+	 when 2 => Choice_T1 := B; L2 := (A,C); M := B;
76
+	 when 3 => Choice_T1 := C; L2 := (A,B); M := C;
77
+      end case;
78
+      --Fin Tour 1
79
+      
80
+      -- Action Présentateur
81
+      L2(Presentateur(L2)).IS_Open := True;
82
+      L1 := ((M) & L2);
83
+      
84
+      for J in L1'Range loop
85
+	 if L1(J).IS_Open then
86
+	    Put_Line("Porte " & L1(J).Name & " ouverte" );
87
+	 elsif 
88
+	    
89
+	 end if;
90
+      end loop;
91
+      --##
92
+      --## ALGORITHME NON FINI
93
+      --##
94
+      --##
95
+      return A.Hide_Goat;
96
+   end Game;
97
+   
98
+   
99
+begin
100
+   RB.Reset(HasardRB);
101
+   RT.Reset(HasardRT);
102
+   
103
+   if Game then
104
+      Put("OK");
105
+   end if;
106
+end Monty_Hall;

+ 4236
- 0
autres/nb_premiers/list.txt
File diff suppressed because it is too large
View File


BIN
autres/nb_premiers/nb_premiers View File


+ 93
- 0
autres/nb_premiers/nb_premiers.adb View File

@@ -0,0 +1,93 @@
1
+with Ada.Text_Io;
2
+use Ada.Text_Io;
3
+
4
+with Ada.Numerics.Elementary_Functions;
5
+use Ada.Numerics.Elementary_Functions;
6
+
7
+procedure Nb_Premiers is
8
+   
9
+   -- Variables parametres
10
+   subtype SIZE is Integer range 1..18;
11
+   
12
+   
13
+   -- Fonction de test de nb premiers
14
+   function Is_Prime(N : Long_Integer) return Boolean is
15
+      Prime : Boolean := True;
16
+   begin
17
+      if N mod Long_Integer(2) = 0 and N /= 2 then
18
+	 Prime := False;
19
+      else
20
+	 for I in 2..(Long_Integer(1.0+Sqrt(Float(N)))/2) loop
21
+	    if N mod Long_Integer(2*I-1) = 0 then 
22
+	       Prime := False;
23
+	       exit;
24
+	    end if;
25
+	 end loop;
26
+      end if;
27
+      return prime;
28
+   end Is_Prime;
29
+   
30
+   -- Affichage nombre premier
31
+   procedure IP(N : Long_Integer) is
32
+   begin
33
+      if Is_Prime(N) then
34
+	 Put_Line(Long_Integer'Image(N) & " premier");
35
+      else
36
+	 Put_Line(Long_Integer'Image(N) & " n'est pas premier");
37
+      end if;
38
+   end IP;
39
+   
40
+   -- Afficher les nb troncables d'une certaine taille
41
+   procedure Aff_Troncable(N : Long_Integer) is
42
+      --T_Min : constant Natural := 1; --Nombre de digits des nombres affichés
43
+   begin
44
+      Put_Line(Long_Integer'Image(N));
45
+   end Aff_Troncable;
46
+   
47
+   
48
+   -- Puissance de 10
49
+   function mode(M : Long_Integer) return Long_Integer is 
50
+      I : Long_Integer := 0;
51
+      N : Long_Integer := M;
52
+   begin
53
+      while N >= 0 loop
54
+	 N := N - 10**(Integer(I));
55
+	 I := I + 1;
56
+      end loop;
57
+      return I;
58
+   end mode;
59
+   
60
+   
61
+   -- Recherche de nombres premiers tromcables
62
+   procedure Troncable(N : Long_Integer) is
63
+      N3 : Long_Integer := 0;
64
+   begin
65
+      if Is_Prime(N) then
66
+	 Aff_Troncable(N);
67
+	 if N < (Long_Integer'Last / 100) then
68
+	    for I in 1..9 loop
69
+	       N3 := 10;
70
+	       for J in 1..(Mode(N) - 2) loop
71
+		  N3 := N3 * 10;
72
+	       end loop;	    
73
+	       Troncable(N + Long_Integer(I)*N3);
74
+	    end loop;
75
+	 elsif N < (Long_Integer'Last / 11) then
76
+	    for I in 1..8 loop
77
+	       N3 := 10;
78
+	       for J in 1..(Mode(N) - 2) loop
79
+		  N3 := N3 * 10;
80
+	       end loop;	    
81
+	       Troncable(N + Long_Integer(I)*N3);
82
+	    end loop;
83
+	 end if;
84
+      end if;
85
+   end Troncable;
86
+   
87
+   
88
+begin
89
+   Troncable(Long_Integer(2));
90
+   Troncable(Long_Integer(3));
91
+   Troncable(Long_Integer(5));
92
+   Troncable(Long_Integer(7));
93
+end Nb_Premiers;

+ 31
- 0
readme.md View File

@@ -0,0 +1,31 @@
1
+# cours_ada
2
+Partage de mes essais en Ada dans le cadre des cours de 2ème année MIC à l'INSA Toulouse et du [cours d'openclassroom](https://openclassrooms.com/fr/courses/900279-apprenez-a-programmer-avec-ada).
3
+Le code est sous licence GNU GPL 3, les cours de l'INSA et d'openclassroom appartiennent à leurs propriétaires respectifs.
4
+
5
+### Index - Cours INSA du semestre 4
6
+* TD1 : Pointeurs et listes :
7
+	* semestre4/listes
8
+	* semestre4/listes_doulement_chaine
9
+* TD2 : Paquetages :
10
+	* semestre4/paquetages
11
+* TD3 : Généricité :
12
+	* semestre4/listes_ordonnees
13
+* TD4 : Arbres binaires
14
+	* semestre4/arbres_binaires
15
+
16
+* TP1 : Piles et expressions postfixées
17
+	* semestre4/TP1_piles
18
+* TP2 : Paquetages de listes ordonnées d'entiers, type privé & limité privé
19
+	* semestre4/TP2_listes_ordonnees_type_LP
20
+* TP3 : Paquetages génériques
21
+	* semestre4/TP3_paquetages_generiques
22
+* TP4 : Arbres binaires et paquetages génériques
23
+	* semestre4/TP4_arbres_binaires_genericite
24
+* TP5 : Tri par tas
25
+	* semestre4/TP5_tri_par_tas
26
+* Correction CC1 : Files / LIFO
27
+	* semestre4/cc1
28
+ 
29
+### Travaux divers
30
+(Obsolète) Partage de quelques travaux personnels, voir [travaux.md](travaux.md). 
31
+

BIN
semestre3/Kaprekar/main View File


+ 204
- 0
semestre3/Kaprekar/main.adb View File

@@ -0,0 +1,204 @@
1
+with ada.Text_IO, Ada.Integer_Text_IO;
2
+with ada.Calendar;
3
+
4
+use ada.Text_IO;
5
+
6
+procedure Main is
7
+   
8
+   -- Type & package
9
+   subtype chiffre is Natural range 0..9;
10
+   type nbr is array (Integer range <>) of Integer;
11
+   package date renames ada.Calendar;
12
+   
13
+   
14
+   -- Variables globales
15
+   FND : constant Integer := 100; -- FIND
16
+   WST : constant Integer := FND - 1;  -- WRITE START
17
+   
18
+   
19
+   data_dect : nbr(1..FND);
20
+   -- Ce tableau contient des nombres pour de la detection de boucle
21
+   -- Le rang WST et FND sont des rangs de services
22
+   
23
+   
24
+   -- Procédure de detection de boucle, utilise la base de données data_dect
25
+   procedure detect_loop (int : in Integer) is
26
+      debut_ecriture : Integer := data_dect(WST);
27
+   begin
28
+      for i in data_dect'First..(WST - 1) loop
29
+         if int = data_dect(i) then
30
+            data_dect(FND) := 1;
31
+         end if;
32
+      end loop;
33
+
34
+      data_dect(debut_ecriture) := int;
35
+      data_dect(WST) := data_dect(WST) + 1;
36
+
37
+      if data_dect(WST) >= WST then
38
+         raise Storage_Error;
39
+      end if;
40
+
41
+   end detect_loop;
42
+   
43
+   
44
+   -- Tri par ordre croissant un tableau d'integer
45
+   procedure tri (tab : in out nbr) is
46
+      buffer : nbr(tab'Range);
47
+      valeur : Integer := 0;
48
+      pos : Integer := 0;
49
+   begin
50
+      for k in tab'Range loop
51
+         valeur := 0;
52
+         pos := tab'last;
53
+         for i in tab'range loop
54
+            if tab(i) >= valeur then
55
+               pos := i;
56
+               valeur := tab(i);
57
+            end if;
58
+         end loop;
59
+         tab(pos):=0;
60
+         buffer(k) := valeur;
61
+      end loop;
62
+      tab := buffer;
63
+   end tri;
64
+   
65
+   
66
+   -- Tri par ordre décroissant
67
+   procedure tri_inverse (tab : in out nbr) is
68
+      buffer : nbr(tab'Range);
69
+   begin
70
+      tri(tab);
71
+      for i in tab'range loop
72
+         buffer(i):=tab(tab'last-(i-1));
73
+      end loop;
74
+      tab:=buffer;
75
+   end tri_inverse;
76
+
77
+   -- Partie opérative de l'algo de Kaprekar (nombre en deux tableaux triés, affiche et retourne la différence des nombres
78
+   function operation (nombre : integer; dimension : Integer) return Integer is
79
+      ord_croiss : nbr(1..dimension);
80
+      ord_droiss : nbr(1..dimension);
81
+      nombre_croiss : Integer := 0;
82
+      nombre_droiss : Integer := 0;
83
+      nombre_stock : Integer := nombre;
84
+   begin
85
+      -- On met le nombre dans un tableau
86
+      for k in 1..dimension loop
87
+         ord_croiss(k) := (nombre_stock/10**(dimension-(k)));
88
+         nombre_stock := nombre_stock - ord_croiss(k)*10**(dimension-k);
89
+      end loop;
90
+
91
+      --tri
92
+      ord_droiss := ord_croiss;
93
+      tri(ord_croiss);
94
+      tri_inverse(ord_droiss);
95
+
96
+      for j in 1..dimension loop
97
+         nombre_droiss := nombre_droiss + ord_droiss(j) * (10**(dimension - (j)));
98
+         nombre_croiss := nombre_croiss + ord_croiss(j) * 10**(dimension -(j));
99
+
100
+      end loop;
101
+
102
+      Put_Line("N1 = " & Integer'Image(nombre_croiss) & " N2 = " & Integer'Image(nombre_droiss) & " N1 - N2 = " & Integer'Image(nombre_croiss - nombre_droiss));
103
+
104
+      return nombre_croiss - nombre_droiss;
105
+   end operation;
106
+   
107
+   
108
+   -- Permet de déterminer la taille d'un nombre
109
+   function nb_digits (nombre : Integer) return Integer is
110
+      dimension_nok : Boolean := true;
111
+      dimension : Integer := 0;
112
+      i : Integer := 0;
113
+   begin
114
+      while dimension_nok loop
115
+         if (nombre / 10**i) <= 0 then
116
+            dimension_nok := false;
117
+            dimension := i;
118
+         else
119
+            i := i + 1;
120
+         end if;
121
+      end loop;
122
+
123
+      if dimension = 0 then
124
+         dimension := 1;
125
+      end if;
126
+
127
+      return dimension;
128
+   end nb_digits;
129
+   
130
+   
131
+   -- Procédure de coordination des fonctions de l'algorithme et de la detection de boucle 
132
+   procedure kaprekar (nombre : in out Integer) is
133
+      dimension_nok : Boolean := true;
134
+      dimension : Integer := 0;
135
+      i : Integer := 0;
136
+      temp : Integer := nombre;
137
+   begin
138
+      nombre := temp + 1;
139
+
140
+      while nombre /=temp loop
141
+         dimension := nb_digits(temp);
142
+         nombre := temp;
143
+         temp := operation(temp, dimension);
144
+
145
+         detect_loop(temp);
146
+         if data_dect(FND) = 1 then
147
+            Put_Line("Boucle dans l'algorithme");
148
+            nombre := temp;
149
+         end if;
150
+
151
+
152
+         delay 0.2;
153
+         Put_Line("--------------");
154
+      end loop;
155
+
156
+
157
+   end kaprekar;
158
+   
159
+   
160
+   -- Procédure de test de la fonction tri
161
+   -- cf ../../Test_tri pour d'autres algorithmes de tri
162
+   procedure test_tri is
163
+      test_tri1 : nbr(1..10) := (5,4,8,3,9,1,6,7,2,0);
164
+      test_tri2 : nbr(1..10) := (5,4,8,6,9,1,6,7,7,0);
165
+   begin
166
+      tri(test_tri2);
167
+      tri_inverse(test_tri1);
168
+
169
+      for i in test_tri1'First..test_tri1'Last loop
170
+         put(Integer'Image(test_tri1(i))& " ");
171
+      end loop;
172
+      Put_Line("");
173
+      for i in test_tri2'First..test_tri2'Last loop
174
+         put(Integer'Image(test_tri2(i))& " ");
175
+      end loop;
176
+      Put_Line("");
177
+   end test_tri;
178
+   
179
+
180
+   nombre: Integer := 0;
181
+begin
182
+   -- Detection de boucle:
183
+   data_dect(WST) := 1; --le premier rang écrit par défaut est le 1
184
+   data_dect(FND) := 0; --aucune boucle n'est trouvé au début
185
+
186
+   --Put_Line("Test du programme :");
187
+   --test_tri;
188
+   
189
+   
190
+   --
191
+   Put("Algorithme de Kaprekar. Saisir un nombre : ");
192
+   Ada.Integer_Text_IO.Get(nombre);
193
+
194
+   kaprekar(nombre);
195
+
196
+   Put_Line("ALGORITHME FINI");
197
+   
198
+   
199
+   -- Exceptions
200
+exception
201
+   when Constraint_Error => Put_Line("Nombre donné non valide.");
202
+   when Storage_Error => Put_Line("DATA_BASE_TOO_SHORT, data_dect(WST):"&Integer'Image(data_dect(WST)));
203
+   when others => Put_line("Nombre non valide ou trop grand !");
204
+end Main;

BIN
semestre3/Test_Tri/test_tri View File


+ 288
- 0
semestre3/Test_Tri/test_tri.adb View File

@@ -0,0 +1,288 @@
1
+with ada.Text_IO, Ada.Integer_Text_IO;
2
+with Ada.Numerics.Discrete_Random;
3
+with Ada.Command_Line;
4
+
5
+use ada.Text_IO;
6
+use Ada.Command_Line;
7
+
8
+-- Lib C pour intefacer avec le system
9
+with Interfaces.C; use Interfaces.C;
10
+
11
+procedure Test_Tri is
12
+   
13
+   -- Variables globales
14
+   TMP : constant Duration := 0.05;
15
+   INTE : Integer := 0;
16
+   
17
+   -- Type tableau 
18
+   type nbr is array (Integer range <>) of Integer;
19
+   type Grille is array (Integer range <>, Integer range <>) of character;
20
+   subtype Double is Integer range 0..65535;
21
+   
22
+   -- Pointeurs
23
+   type P_procedure is access procedure (Tab, Aff : in out Nbr);
24
+   
25
+   -- Package pour l'aléatoire
26
+   package Aleatoire is new Ada.Numerics.Discrete_Random(Double);
27
+   use Aleatoire;
28
+   Hasard : Generator;
29
+   
30
+   -- Commandes systeme via C
31
+   function System (Cmd : Interfaces.C.Char_Array) return Interfaces.C.int;
32
+   pragma Import (C, System, "system");
33
+   
34
+   
35
+   -- Procédure d'affichage d'un tableau de manière graphique
36
+   procedure Aff (Tab : in  Nbr) is
37
+      Hauteur : constant Integer := 40;
38
+      Value : Integer := 0;
39
+      G : Grille(Tab'First..Hauteur, Tab'range) := (others => (others => ' '));
40
+      Max : Integer := 0;
41
+      Err : Interfaces.C.int;
42
+   begin
43
+      Err := System("clear");
44
+      -- Recherche du max
45
+      for K in Tab'Range loop
46
+	 if Value < Tab(K) then
47
+	    Max := K;
48
+	    Value := Tab(K);
49
+	 end if;
50
+      end loop; 
51
+      Value := 0;
52
+      -- Préparation affichage
53
+      for I in Tab'Range loop
54
+	 Value := ((Tab(I)*Hauteur)/(Tab(Max)+1));
55
+	 for J in G'First(2)..Value loop
56
+	    G(J,I) := '|';
57
+	 end loop;
58
+      end loop;
59
+      --Affichage
60
+      for H in G'Range(1) loop
61
+	 for V in G'Range(2) loop
62
+	    Put(G(G'Last-H+1,V) & "");
63
+	 end loop;
64
+	 New_Line;
65
+      end loop;
66
+      --delay 0.05;
67
+   end Aff;
68
+   
69
+   
70
+   -- Procédure de tri d'un tableau (Tri bulle)
71
+   procedure Tri_Bulle (Tab, Affi : in out Nbr) is
72
+      K : Integer := 0; -- buffer
73
+   begin
74
+      for J in Tab'Range loop
75
+	 for I in Tab'First..(Tab'Last - 1) loop
76
+	    if Tab(I + 1)  < Tab(I) then
77
+	       K := Tab(I + 1);
78
+	       Tab(I + 1) := Tab(I);
79
+	       Tab(I) := K;
80
+	    end if;
81
+	 end loop;
82
+	 Aff(Tab);
83
+	 delay TMP;
84
+      end loop;
85
+   end Tri_Bulle;
86
+   
87
+   
88
+   -- Tri selection
89
+   procedure Tri_Selection (Tab, Affi : in out Nbr) is
90
+      VMin : Integer := Integer'last;
91
+      Min : Integer := 0;
92
+      Buffer : Integer;
93
+   begin
94
+      for J in Tab'Range loop
95
+	 Vmin := Integer'Last;
96
+	 for I in ((Tab'First+J-1))..Tab'last loop
97
+	    if VMin > Tab(I) then
98
+	       VMin := Tab(I);
99
+	       Min := I;
100
+	    end if;
101
+	 end loop;
102
+	 Buffer := Tab(Tab'First+J-1);
103
+	 Tab(Tab'First+J-1) := Tab(Min);
104
+	 Tab(Min) := Buffer;
105
+	 Aff(Tab);
106
+	 delay TMP;
107
+      end loop;
108
+   end Tri_Selection;
109
+   
110
+   
111
+   -- Tri selection - Version inversée
112
+   procedure Tri_Selection_Inv (Tab, Affi : in out Nbr) is
113
+      VMax : Integer := 0;
114
+      Max : Integer := 0;
115
+      Buffer : Integer;
116
+   begin
117
+      for J in Tab'Range loop
118
+	 Vmax := 0;
119
+	 for I in ((Tab'First+J-1))..Tab'last loop
120
+	    if VMax < Tab(I) then
121
+	       VMax := Tab(I);
122
+	       Max := I;
123
+	    end if;
124
+	 end loop;
125
+	 Buffer := Tab(Tab'First+J-1);
126
+	 Tab(Tab'First+J-1) := Tab(Max);
127
+	 Tab(Max) := Buffer;
128
+	 Aff(Tab);
129
+	 delay TMP;
130
+      end loop;
131
+   end Tri_Selection_Inv;
132
+   
133
+   -- Quicksort
134
+   procedure Quicksort (A, affi : in out Nbr) is
135
+      procedure Swap(Left, Right : Natural) is
136
+	 Temp : Integer := A (Left);
137
+      begin
138
+	 A (Left) := A (Right);
139
+	 A (Right) := Temp;
140
+      end Swap;
141
+      
142
+   begin
143
+      if A'Length > 1 then
144
+	 declare
145
+	    Pivot_Value : Integer := A (A'First);
146
+	    Right : Natural := A'Last;
147
+	    Left : Natural := A'First;
148
+	 begin
149
+	    loop
150
+	       while Left < Right and not (Pivot_Value < A (Left)) loop
151
+		  Left := Natural'Succ (Left);
152
+	       end loop;
153
+	       while Pivot_Value < A (Right) loop
154
+		  Right := Natural'Pred (Right);
155
+	       end loop;
156
+	       exit when Right <= Left;
157
+	       Swap (Left, Right);
158
+	       Left := Natural'Succ (Left);
159
+	       Right := Natural'Pred (Right);
160
+	    end loop;
161
+	    if Right = A'Last then
162
+	       Right := Natural'Pred (Right);
163
+	       Swap (A'First, A'Last);
164
+	    end if;
165
+	    if Left = A'First then
166
+	       Left := Natural'Succ (Left);
167
+	    end if;
168
+	    Affi(A'First..A'Last) := A;
169
+	    Aff(Affi);
170
+	    Quicksort (A (A'First .. Right), Affi);
171
+	    Quicksort (A (Left .. A'Last), Affi);
172
+	 end;
173
+      end if;
174
+   end Quicksort;
175
+   
176
+   -- Tri stupide
177
+   procedure Tri_Stupide(T, Affi : in out Nbr) is
178
+      function Ordonne(T : in Nbr) return Boolean is 
179
+	 Ord : Boolean := True;
180
+	 I : Integer := T'First;
181
+      begin
182
+	 -- Ordonné ?
183
+	 while Ord and I < T'last loop
184
+	    if T(I) > T(I+1) then
185
+	       Ord := False;
186
+	    end if;
187
+	    I := I + 1;
188
+	 end loop;
189
+	 return Ord;
190
+      end Ordonne;
191
+      -- Mélange
192
+      procedure Melange(T : in out Nbr) is
193
+	 J, Aux : Integer;
194
+      begin
195
+	 INTE := INTE + 1;
196
+	 for I in T'Range loop
197
+	    J := (Random(Hasard) mod I) + 1;
198
+	    if J < I then
199
+	       Aux := T(I);
200
+	       T(I) := T(J);
201
+	       T(J) := Aux;
202
+	    end if;
203
+	 end loop;
204
+      end Melange;
205
+   begin
206
+      while not Ordonne(T) loop
207
+	 Melange(T);
208
+	 Aff(T);
209
+	 delay TMP;
210
+      end loop;
211
+      Aff(T);
212
+   end Tri_Stupide;
213
+   
214
+   
215
+   -- Test de la procédure tri
216
+   procedure Test_Tri (F : P_Procedure) is
217
+      test_tri1 : nbr(1..80);
218
+   begin
219
+      Put_Line("------------------");
220
+      for J in Test_Tri1'Range loop
221
+	 Test_Tri1(J) := Random(Hasard);
222
+      end loop;
223
+      
224
+      F(Test_Tri1, Test_tri1);
225
+   end Test_tri;
226
+   
227
+   F : P_Procedure;
228
+   F1 : P_Procedure;
229
+   F2, F3 : P_Procedure;
230
+   Iteration : Integer := 1;
231
+   Go : Boolean := False;
232
+   Err : Interfaces.C.int;
233
+begin
234
+   --Renitialisation du générateur
235
+   Reset(Hasard);
236
+   if Argument_Count = 1 then
237
+      if Argument(1) = "--help" then
238
+	 Put_Line("Algorithme d'affichage d'algorithme de tri");
239
+	 Put_Line("Compatible avec les sytemes UNIX uniquement");
240
+	 New_Line;
241
+	 Put_Line("Le nombre d'itération peut être donné en argument");
242
+	 Put_Line("Argument -r pour un tri inverse");
243
+      elsif Argument(1) = "-r" then
244
+	 F1 := Tri_Selection_Inv'Access;
245
+	 Test_Tri(F1);
246
+      else
247
+	 Iteration := Integer'Value(Argument(1));
248
+	 Go := True;
249
+      end if;
250
+   else
251
+      New_Line;
252
+      --Put("Nbr de boucles : ");
253
+      --Ada.Integer_Text_IO.Get(Iteration);
254
+      Go := True;
255
+   end if;
256
+   
257
+   if Go then
258
+      for I in 1..Iteration loop
259
+	 --Test des fonctions
260
+	 F := Tri_Stupide'Access;
261
+	 F1 := Tri_Bulle'Access;
262
+	 F2 := Tri_Selection'Access;
263
+	 F3 := Quicksort'Access;
264
+	 
265
+	 Err := System("clear");
266
+	 Put_Line("TRI SELECTION :");
267
+	 delay 2.0;
268
+	 Test_Tri(F2);
269
+	 
270
+	 Err := System("clear");
271
+	 Put_Line("TRI BULLE :");
272
+	 delay 2.0;
273
+	 Test_Tri(F1); 
274
+	 
275
+	 Err := System("clear");
276
+	 Put_Line("TRI RAPIDE :");
277
+	 delay 2.0;
278
+	 Test_Tri(F3);
279
+	 
280
+	 Err := System("clear");
281
+	 Put_Line("TRI STUPIDE :");
282
+	 delay 2.0;
283
+	 Test_Tri(F);
284
+      end loop;
285
+   end if;
286
+   
287
+   Put_Line(Integer'Image(INTE));
288
+end Test_Tri;

BIN
semestre3/chaine_caracteres/chaine View File


+ 100
- 0
semestre3/chaine_caracteres/chaine.adb View File

@@ -0,0 +1,100 @@
1
+with ada.Text_IO, Ada.Integer_Text_IO;
2
+with ada.Calendar;
3
+
4
+use ada.Text_IO;
5
+
6
+procedure Chaine is
7
+   -- Sous-types & variables globales
8
+   LMT : constant Integer := 100; -- Taille maximun du traitement
9
+   Type Buffer is array (1..LMT) of Character;
10
+   type Position is record 
11
+      Debut : Integer;
12
+      Fin : Integer;
13
+   end record;
14
+   
15
+   
16
+   -- Lecture d'entrée console
17
+   function Lire_Entree return String is
18
+      Saisie : String (1..LMT);
19
+      Last : Natural;
20
+   begin
21
+      Get_Line(Saisie, Last);
22
+      declare
23
+	 Phrase : String(Saisie'First..(Last+2));
24
+      begin
25
+	 Phrase(Phrase'First) := ' ';
26
+	 Phrase(Phrase'Last) := ' ';
27
+	 Phrase((Phrase'First+1)..(Phrase'Last-1)) := Saisie((Saisie'First)..Last);
28
+	 return Phrase;
29
+      end;
30
+   end Lire_Entree;
31
+   
32
+   
33
+   -- Extrait le premier mot d'un string
34
+   function Extraire_Mot(Text : in out String; Trouve : out Boolean) return Position is
35
+      I : Integer := 1;
36
+      Pos : Position;
37
+      Fin : Boolean := False;
38
+   begin
39
+      Trouve := True;
40
+      
41
+      while Text(I) = ' ' and not Fin loop
42
+	 I := I + 1;
43
+	 if I >= Text'Last then 
44
+	    Trouve := False;
45
+	    Fin := True;
46
+	 end if;
47
+      end loop;
48
+      
49
+      Pos.Debut := I;
50
+      
51
+      while not Fin loop
52
+	 if Text(I) = ' ' then
53
+	    Fin := True;
54
+	 else
55
+	    I := I + 1;
56
+	 end if;
57
+      end loop;
58
+      
59
+      Pos.Fin := I;
60
+      
61
+      for J in Text'First..I loop
62
+	 Text(J) := ' ';
63
+      end loop;
64
+
65
+      return Pos;
66
+   End Extraire_Mot;
67
+   
68
+   
69
+   -- Procedure de recherche de mot
70
+   procedure Fnd_Mot (Txt :  String) is
71
+      Fini : Boolean := False;
72
+      Compteur : Integer := 0;
73
+      Pos : Position;
74
+      Trouve : Boolean;
75
+      Text : String(Txt'Range) := Txt; -- question de compatibilité
76
+      
77
+   begin
78
+      while not Fini loop
79
+	 Pos := Extraire_Mot(Text, Trouve);
80
+	 
81
+	 if not Trouve then
82
+	    Fini := True;
83
+	    Put_Line("Extraction terminée");
84
+	 else 
85
+	    Compteur := Compteur + 1;
86
+	    Put("Mot n°" & Integer'Image(Compteur) & " trouvé : ");
87
+	    for I in Pos.Debut..Pos.Fin loop
88
+	       Put(Txt(I));
89
+	       Text(I) := ' ';
90
+	    end loop;
91
+	    New_Line;
92
+	 end if;
93
+      end loop;
94
+   end Fnd_Mot;
95
+   
96
+   
97
+begin
98
+   Put_Line("Saisir une phrase : ");
99
+   Fnd_Mot(Lire_Entree);
100
+end Chaine;

+ 11
- 0
semestre3/piles/afficher_test.adb View File

@@ -0,0 +1,11 @@
1
+with Ada.Text_Io;
2
+
3
+procedure Afficher_Test(Objet_du_Test, Attendu, Obtenu : in  String) is
4
+begin
5
+   Ada.Text_Io.New_Line;
6
+   Ada.Text_Io.Put_Line("-----------------------------------------------------------");
7
+   Ada.Text_Io.Put_Line(Objet_du_Test);
8
+   Ada.Text_Io.Put_Line("Resultat attendu : " & Attendu);
9
+   Ada.Text_Io.Put_Line("Resultat obtenu  : " & Obtenu);
10
+   Ada.Text_Io.New_Line;
11
+end Afficher_Test;

+ 1
- 0
semestre3/piles/afficher_test.ads View File

@@ -0,0 +1 @@
1
+procedure Afficher_Test(Objet_du_Test, Attendu, Obtenu : in  String);

+ 104
- 0
semestre3/piles/piles_entiers.adb View File

@@ -0,0 +1,104 @@
1
+-- Auteurs : P. Esquirol
2
+-- Version du 30/01/2019
3
+
4
+-- Sous-programmes à compléter
5
+-- Init_Pile
6
+-- Est_Vide
7
+-- Sommet
8
+-- Empiler
9
+-- Depiler
10
+-- Hauteur
11
+-- Liste_To_String
12
+-- To_String
13
+
14
+with Unchecked_Deallocation;
15
+
16
+package body Piles_Entiers is
17
+
18
+   procedure Free is new Unchecked_Deallocation(Cellule, Liste);
19
+   -- Desallocation d'une Cellule pointee par un pointeur de type Liste
20
+   -- Procedure utilisee lors des operations Depiler(P) et Vider(P)
21
+
22
+   procedure Init(P : in out Pile) is
23
+   -- Ne fait rien si P est deja vide a l'appel
24
+   -- Sinon efface tous les elements de P (en
25
+   -- recuperant la memoire allouee)
26
+   -- et retourne la pile vide
27
+   begin
28
+      null;          -- A COMPLETER;
29
+   end Init;
30
+
31
+   function Est_Vide(P : in Pile) return Boolean is
32
+   -- Retourne vrai si la pile est vide, faux sinon
33
+   begin
34
+      return true;   -- A COMPLETER
35
+   end Est_Vide;
36
+
37
+   function Sommet(P : in Pile) return Integer is
38
+   -- Retourne le premier element de P (situe au sommet)
39
+   begin
40
+      return 666;    -- A COMPLETER
41
+   end Sommet;
42
+
43
+   procedure Empiler(E : in Integer; P : in out Pile) is
44
+   -- Empile E au dessus de P ; E devient le nouveau sommet
45
+   begin
46
+      null;          -- A COMPLETER
47
+   end Empiler;
48
+
49
+   procedure Depiler(P: in out Pile) is
50
+   -- Efface le sommet de P ; attention, penser a recuperer
51
+   -- la memoire associee a la cellule a effacer
52
+   begin
53
+      null;          -- A COMPLETER
54
+   end Depiler;
55
+
56
+   function Hauteur(P : in Pile) return Natural is
57
+   -- Calculer la hauteur en comptant le nombre d'elements depilables
58
+   -- n'est pas efficace. Cette fonction retourne directement le champ
59
+   -- hauteur du record associe a une pile
60
+   begin
61
+      return 0;      -- A COMPLETER
62
+   end Hauteur;
63
+
64
+   function Liste_To_String(L : Liste) return String is
65
+   -- Convertit une liste d'entiers en une chaine de caracteres
66
+   begin
67
+      return "";     -- A COMPLETER
68
+   end Liste_To_String;
69
+
70
+   function To_String(P : in Pile) return String is
71
+   -- Convertit une pile d'entiers en une chaine de caracteres
72
+   begin
73
+      return "";     -- A COMPLETER
74
+   end To_String;
75
+
76
+   function "="(P1,P2 : in Pile) return Boolean is
77
+   -- Verifie que les piles sont identiques (memes elements et meme ordre)
78
+   begin
79
+      return FALSE;  -- A COMPLETER
80
+   end "=";
81
+
82
+
83
+
84
+
85
+
86
+--   procedure Free_Liste(L : in out Liste) is
87
+--   -- Desallocation de toutes les Cellules d'une Liste
88
+--   begin
89
+--      if L /= null then
90
+--         Free_Liste(L.All.Suiv);  -- desallocation de la liste suivante PUIS
91
+--         Free(L);                 -- desallocation de le premiere cellule
92
+--      end if;
93
+--      L := null;                  -- en principe c'est le cas apres Free(L)
94
+--   end Free_Liste;
95
+
96
+--   procedure Vider(P : in out Pile) is   -- pas indispensable pour le paquetage
97
+--   begin
98
+--                        --A COMPLETER EVENTUELLEMENT (reutiliser Free_Liste)
99
+--   end Vider;
100
+
101
+end Piles_Entiers;
102
+
103
+
104
+

+ 63
- 0
semestre3/piles/piles_entiers.ads View File

@@ -0,0 +1,63 @@
1
+-- Auteurs : P. Esquirol
2
+-- Version du 30/01/2019
3
+
4
+package Piles_Entiers is
5
+
6
+   type Pile is limited private;
7
+
8
+   Pile_Vide : exception;
9
+   -- exception levee si on tente d'acceder au sommet d'une pile vide
10
+   -- ou si on tente de depiler une pile vide.
11
+
12
+   -- ****************************************
13
+   -- OPERATIONS INDISPENSABLES DU T.A.D. PILE
14
+   -- ****************************************
15
+
16
+   procedure Init(P : in out Pile);
17
+   -- Ne fait rien si P est deja vide a l'appel
18
+   -- Sinon efface tous les elements de P (en
19
+   -- recuperant la memoire allouee)
20
+   -- et retourne la pile vide
21
+
22
+   function  Est_Vide(P : in Pile) return Boolean;
23
+   -- Retourne vrai si la pile est vide, faux sinon
24
+
25
+   function  Sommet(P : in Pile) return Integer;
26
+   -- Retourne le premier element de P (situe au sommet)
27
+
28
+   procedure Empiler(E : in Integer; P : in out Pile);
29
+   -- Empile E au dessus de P ; E devient le nouveau sommet
30
+
31
+   procedure Depiler(P: in out Pile);
32
+   -- Efface le sommet de P ; attention, penser a recuperer
33
+   -- la memoire associee a la cellule a effacer
34
+
35
+   -- **************************************
36
+   -- OPERATIONS FACULTATIVES DU T.A.D. PILE
37
+   -- **************************************
38
+
39
+   function Hauteur(P : in Pile) return Natural;
40
+   -- Calculer la hauteur en comptant le nombre d'elements depilables
41
+   -- n'est pas efficace. Cette fonction accede directement au champ
42
+   -- hauteur du record associe a une pile
43
+
44
+   function To_String(P : in Pile) return String;
45
+   -- Convertit une pile d'entiers en une chaine de caracteres
46
+
47
+   function "="(P1,P2 : in Pile) return boolean;
48
+   -- Verifie que les piles sont identiques (memes elements et meme ordre)
49
+
50
+private
51
+   type Cellule;
52
+   type Liste   is access Cellule;
53
+   type Cellule is record
54
+        Info : Integer;
55
+        Suiv : Liste;
56
+   end record;
57
+
58
+   type Pile is record
59
+        Debut  : Liste   := null;
60
+        Hauteur: Natural := 0;
61
+   end record;
62
+
63
+end Piles_Entiers;

+ 98
- 0
semestre3/piles/tests_piles_entiers.adb View File

@@ -0,0 +1,98 @@
1
+-- Auteurs : P. Esquirol
2
+-- Version du 30/01/2019
3
+
4
+with Ada.Text_Io, Piles_Entiers, Afficher_Test;
5
+use  Ada.Text_Io, Piles_Entiers;
6
+
7
+procedure Tests_Piles_Entiers is
8
+begin
9
+   ---------------------------------------------------------
10
+   -- 1. Tests apres la declaration et acces a une pile vide
11
+   ---------------------------------------------------------
12
+   Put_Line("Test 1 : apres Declaration d'une pile P");
13
+   declare
14
+      P : Pile;
15
+   begin
16
+      Afficher_Test("Est_Vide(P)  ?", "TRUE", Boolean'Image(Est_Vide(P)));
17
+      Afficher_Test("Hauteur(P)   ?", "0   ", Integer'Image(Hauteur(P)));
18
+      Afficher_Test("To_String(P) ?", "    ", To_String(P));
19
+   end;
20
+   New_Line;
21
+   Put_Line("Test 2: Tentative d'acces au sommet d'une pile vide");
22
+   declare
23
+      P  : Pile;
24
+      Nb : Integer;
25
+   begin
26
+      Nb := Sommet(P);
27
+      Afficher_Test("Sommet(P)  ?", "levee exception", Integer'Image(Nb));
28
+      Put_Line("bizarre ... l'exception n'a pas ete levee ... ");
29
+   exception
30
+      when Pile_Vide =>
31
+      Put_Line("ok, l'exception Pile_Vide a ete levee !!");
32
+   end;
33
+
34
+	---------------------
35
+	-- 2. Tests d'empiler
36
+	---------------------
37
+   declare
38
+      P : Pile;
39
+   begin
40
+      New_Line;
41
+      Put_Line("Test 3 : Empiler 10 entiers ");
42
+      --
43
+      --   ...  <<< A COMPLETER
44
+      --
45
+   end;
46
+
47
+	--------------------------------
48
+	-- 3. Tests de Depiler et Sommet
49
+	--------------------------------
50
+   declare
51
+      P  : Pile;
52
+      Nb : Integer;
53
+   begin
54
+      -- Empiler 10 elements
55
+      --
56
+      --   ...  <<< A COMPLETER
57
+      --
58
+      New_Line;
59
+      Put_Line("Test 4: Affichage du sommet et depilement pendant 10 fois ...");
60
+
61
+      -- Verifier que la pile est bien vide apres 10 appels a Depiler
62
+      --
63
+      --   ...  <<< A COMPLETER
64
+      --
65
+      New_Line;
66
+      Put_Line("Test 5: Tentative de depilement d'une pile vide ...");
67
+      --
68
+      --   ...  <<< A COMPLETER
69
+      --
70
+      end;
71
+
72
+	-----------------------------------
73
+	-- 4. Test sur l'egalite de 2 piles
74
+	-----------------------------------
75
+	Put_Line("Test 6 : Initialisation de 2 piles P1 et P2, et comparaison, ajout de 10 elements et comparaison");
76
+   declare
77
+      P1, P2 : Pile;
78
+   begin
79
+      null;
80
+      -- P1 et P2 viennent d'etre declarees, elles sont donc vides
81
+      -- Verifier qu'elles sont identiques (P1=P2)
82
+      New_Line;
83
+      Put_Line("Test 6 : Deux piles vides sont-elles identiques ?");
84
+      --
85
+      --   ...  <<< A COMPLETER
86
+      --
87
+      New_Line;
88
+      Put_line("On empile desormais 10 entiers 1..10 sur les 2 piles");
89
+      --
90
+      --   ...  <<< A COMPLETER
91
+      --
92
+      New_Line;
93
+      Put_Line("Test 7 : Deux piles contenant 1..10 sont-elles identiques ?");
94
+      --
95
+      --   ...  <<< A COMPLETER
96
+      --
97
+   end;
98
+end Tests_Piles_Entiers;

BIN
semestre3/pointeurs/seance_1_TP+TD/pointeurs View File


+ 298
- 0
semestre3/pointeurs/seance_1_TP+TD/pointeurs.adb View File

@@ -0,0 +1,298 @@
1
+with Ada.Text_IO;
2
+with Ada.Integer_text_IO;
3
+use Ada.Text_IO;
4
+
5
+procedure Pointeurs is
6
+   
7
+   package Int renames Ada.Integer_Text_Io;
8
+   
9
+   --types
10
+   type Cellule;
11
+   type Liste is access Cellule;
12
+   type Cellule is record
13
+      Info : Integer;
14
+      Suiv : Liste;
15
+   end record;
16
+   
17
+   Ajout_Imp : exception;
18
+   
19
+   -----------------------------
20
+   --    TD4 : pointeurs 1    --
21
+   -----------------------------
22
+   
23
+   -- Procédure d'affichage d'une liste
24
+   procedure Afficher (Lst2 : in Liste) is
25
+      Aff : Boolean := True;
26
+      Lst : Liste := Lst2;
27
+   begin
28
+      Put("[ ");
29
+      
30
+      if Lst = null then Aff := False; end if;
31
+      
32
+      while aff loop
33
+	 if Lst.all.Suiv = null then
34
+	    Aff := False;
35
+	 end if;
36
+	 Put(Integer'Image(Lst.all.Info) & " ;");
37
+	 Lst := Lst.all.Suiv;
38
+      end loop;
39
+      Put_Line("]");
40
+   end Afficher;
41
+   
42
+   
43
+   -- Procédure d'affichage en sens inverse d'une liste
44
+   procedure Afficher_Inverse(Lst : in Liste) is
45
+   begin
46
+      if Lst.all.Suiv /= null then
47
+	 Afficher_Inverse(Lst.all.suiv);
48
+      end if;
49
+      Put(Integer'Image(Lst.all.Info) & " ;");
50
+   end Afficher_Inverse;
51
+   
52
+   
53
+   -- Procédure qui compte le nb d'éléments d'une liste
54
+   function Compte (Lst2 : in Liste) return Integer is
55
+      Lst : Liste := Lst2;
56
+      Compteur : Integer := 0;
57
+   begin
58
+      if Lst /= null then 
59
+	 Compteur := 1;
60
+	 while Lst.all.Suiv /= null loop
61
+	    Compteur := Compteur +1;
62
+	    Lst := Lst.all.Suiv;
63
+	 end loop;
64
+      end if;
65
+      --Put_Line("Cette liste possède " & Integer'Image(Compteur) & " cellules");
66
+      return Compteur;
67
+   end Compte;
68
+   
69
+   
70
+   --Procédure d'ajout d'élément en fin de liste de valeur V
71
+   procedure Ajout_Cellule (Lst2 : in out Liste; V : integer) is
72
+      Lst : Liste := Lst2;
73
+   begin
74
+      if Lst = null then
75
+	 Lst2 := new Cellule'(V, null);
76
+      else
77
+	 while Lst.all.Suiv /= null loop
78
+	    Lst := Lst.all.Suiv;
79
+	 end loop;
80
+	 Lst.all.Suiv := new Cellule'(V, null);
81
+      end if;
82
+      --Put_Line("Cellule ajoutée en fin de liste. Valeur : " & Integer'Image(V));
83
+   end Ajout_Cellule;
84
+   
85
+   procedure AJ_Rec (Lst2 : in out Liste; V : Integer) is
86
+   begin
87
+      if Lst2 = null then
88
+	 Lst2 := new Cellule'(V, null);
89
+      else
90
+	 AJ_Rec(Lst2.all.Suiv, V);
91
+      end if;
92
+   end AJ_Rec;
93
+   
94
+   
95
+   -- Fonction de suppression d'un element n
96
+   function Del_Elem (Lst : Liste; N : Integer) return Liste is
97
+      Lst2 : Liste := Lst;
98
+   begin
99
+      if N <= 0 or N > Compte(Lst) then
100
+	 raise Ajout_Imp;
101
+      elsif N = 1 then
102
+	 Lst2 := Lst.all.Suiv;
103
+      else
104
+	 for I in 2..N-1 loop
105
+	    Lst2 := Lst2.all.Suiv;
106
+	 end loop;
107
+	 Lst2.all.suiv := Lst2.all.Suiv.all.Suiv;
108
+	 Lst2 := Lst;
109
+      end if;
110
+      
111
+      return Lst2;
112
+   end Del_Elem;
113
+      
114
+   
115
+   
116
+   -- Procédure qui éclate la liste en une liste de nb pairs et une autre impaires
117
+   function Trier_Liste(Lst : in out Liste) return Liste is
118
+      Lst_Impaire : Liste := null;
119
+      Lst_Buffer : Liste := Lst;
120
+      I : Integer := 1;
121
+      Nb_Enl : Integer := 0;
122
+   begin
123
+      while Lst_Buffer /= null loop
124
+	 if (Float((Lst_Buffer.all.Info / 2)) = Float(Lst_buffer.all.Info)/2.0) then -- si info pair
125
+	    null;
126
+	 else
127
+	    AJ_Rec(Lst_Impaire, Lst_Buffer.all.Info);
128
+	    --Ajout_Cellule(Lst_Impaire, Lst_buffer.all.Info);
129
+	    
130
+	    Lst := Del_Elem(Lst, I - Nb_enl);
131
+	    Nb_Enl := Nb_Enl + 1;
132
+	 end if;
133
+	 Lst_Buffer := Lst_Buffer.all.Suiv;
134
+	 I := I + 1;
135
+      end loop;
136
+      return Lst_impaire;
137
+   end Trier_Liste;
138
+   
139
+   
140
+   
141
+   -----------------------------
142
+   --    TD5 : pointeurs 2    --
143
+   -----------------------------
144
+   
145
+   -- Fonction copie - Version récursive
146
+   function Copie(Lst : in Liste) return Liste is
147
+   begin
148
+      if Lst = null then
149
+	return null;
150
+      else 
151
+	  return new Cellule'(Lst.all.Info, Copie(Lst.all.suiv));
152
+      end if;
153
+   end Copie;
154
+   
155
+   
156
+   -- Procédure de concaténation avec destruction
157
+   procedure Concatenation(L1, L2 : in out Liste) is
158
+      L1buf : Liste := L1;
159
+   begin
160
+      while L1buf.all.suiv /= null loop
161
+	 L1buf := L1buf.all.Suiv;
162
+      end loop;
163
+      L1buf.all.Suiv := L2;
164
+      L2 := null;
165
+   end Concatenation;
166
+   
167
+   
168
+   -- Fonction de concaténation sans destruction
169
+   function Concatenation_safe(L1, L2 : in Liste) return Liste is
170
+      L1buf : Liste := null;
171
+      L1bufaux : Liste := null;
172
+   begin
173
+      L1buf := Copie(L1);
174
+      L1bufaux := L1buf;
175
+      while L1bufaux.all.suiv /= null loop
176
+	 L1bufaux := L1bufaux.all.Suiv;
177
+      end loop;
178
+      L1bufaux.all.Suiv := L2;
179
+      return L1buf;
180
+   end Concatenation_safe;
181
+   
182
+   
183
+   -- Fonction de fusion
184
+   function Fusion(L1, L2 : in Liste) return Liste is
185
+      M1 : Liste := L1;
186
+      M2 : Liste := L2;
187
+      Fusion : Liste := null;
188
+   begin
189
+      while ((M1 /= null) and (M2 /= null)) loop
190
+	 if (M1.all.Info <= M2.all.Info) then
191
+	    Ajout_Cellule(Fusion, M1.all.Info);
192
+	    M1 := M1.all.Suiv;  
193
+	 else
194
+	    Ajout_Cellule(Fusion, M2.all.Info);
195
+	    M2 := M2.all.Suiv;
196
+	 end if;
197
+      end loop;
198
+      
199
+      if M1 = null then
200
+	 Concatenation(Fusion, M2);
201
+      elsif M2 = null then
202
+	 Concatenation(Fusion, M1);
203
+      end if;
204
+      
205
+      return Fusion;
206
+   end Fusion;
207
+   
208
+   
209
+   -- Fonction interactive de saisie de liste
210
+   function Saisir_Liste return Liste is
211
+      N : Integer := 0;
212
+      Lst : Liste := null;
213
+   begin
214
+      Put_Line("Saisir une liste de nombre : ");
215
+      while not End_Of_Line loop
216
+	 Int.Get(N);
217
+	 Ajout_Cellule(Lst, N);
218
+      end loop;
219
+      Put_Line("Liste créée : ");
220
+      Afficher(Lst);
221
+      return Lst;
222
+   end Saisir_Liste;
223
+   
224
+   
225
+   -- Fonction interactive de saisie de liste - version 2 : on utilise pas Ajout_cellule()
226
+   function Saisir_Liste_2 return Liste is
227
+      N : Integer := 0;
228
+      Lst : Liste := null;
229
+      P_Fin : Liste := null;
230
+   begin
231
+      Put_Line("Saisir une liste de nombre : ");
232
+      while not End_Of_Line loop
233
+	 Int.Get(N);
234
+	 if Lst = null then
235
+	    Lst := new Cellule'(N, null);
236
+	    P_Fin := Lst;
237
+	 else
238
+	    P_Fin.all.Suiv := new Cellule'(N, null);
239
+	    P_Fin := P_Fin.all.Suiv;
240
+	 end if;
241
+      end loop;
242
+      Put_Line("Liste créée : ");
243
+      Afficher(Lst);
244
+      return Lst;
245
+   end Saisir_Liste_2;
246
+   
247
+   
248
+   
249
+   
250
+   -----------------------------
251
+   -----------------------------
252
+   
253
+   
254
+   
255
+   L : Liste := null;
256
+   L2 : Liste := null;
257
+   L3 : Liste := null;
258
+   L4 : Liste := null;
259
+begin   
260
+   -----------------------------
261
+   --    TD4 : pointeurs 1    --
262
+   -----------------------------
263
+   for I in 1..10 loop
264
+      Ajout_Cellule(L,I);
265
+   end loop;
266
+   --Ajout_Cellule(L,22);
267
+   --Ajout_Cellule(L,41);
268
+   --
269
+   --Afficher(L);
270
+   --New_Line;
271
+   --Put_Line("Tri des nb pairs et impairs");
272
+   --Afficher(Trier_Liste(L));
273
+   --Afficher(L);
274
+   
275
+   -----------------------------
276
+   --    TD5 : pointeurs 2    --
277
+   -----------------------------
278
+   -- Création des listes
279
+   L2 := Copie(L);
280
+   Ajout_Cellule(L, 22);
281
+   Ajout_Cellule(L3, 3);
282
+   Ajout_Cellule(L3, 5);
283
+   Ajout_Cellule(L3, 7);
284
+   Ajout_Cellule(L3, 9);
285
+   
286
+   --Afficher_Inverse(L);
287
+   --Afficher(L);
288
+   --Afficher(L2);
289
+   --Afficher(L3);
290
+   --Afficher(Concatenation_safe(L, L2));
291
+   --Afficher(L);
292
+   --Afficher(L2);
293
+   --Afficher(Fusion(L3,L));
294
+   
295
+   L4 := Saisir_Liste_2;
296
+exception
297
+   when Ajout_Imp => Put_Line("Tentative d'accès à une cellule inexistante");
298
+end Pointeurs;

BIN
semestre3/pointeurs/seance_2_TP/processeur View File


+ 115
- 0
semestre3/pointeurs/seance_2_TP/processeur.adb View File

@@ -0,0 +1,115 @@
1
+with Ada.Text_IO;
2
+with Ada.Integer_text_IO;
3
+use Ada.Text_IO;
4
+
5
+procedure Processeur is
6
+   
7
+   package Int renames Ada.Integer_Text_Io;
8
+   
9
+   --types
10
+   type process is record
11
+      Num : Integer; --PID
12
+      Dur : Integer; --Quantum
13
+   end record;
14
+   
15
+   type Tache;
16
+   type Liste is access Tache;
17
+   type Tache is record
18
+      Info : Process;
19
+      Suiv : Liste;
20
+   end record;
21
+   
22
+   Q : constant Natural := 1;
23
+   
24
+   --------------------------
25
+   --    TP4 : Séance 2    --
26
+   --------------------------
27
+   
28
+      -- Procédure d'affichage d'une liste
29
+   procedure Afficher (Lst2 : in Liste) is
30
+      Aff : Boolean := True;
31
+      Lst : Liste := Lst2;
32
+      Debut : Integer := 0;
33
+   begin
34
+      Put("    [ ");
35
+      
36
+      if Lst = null then Aff := False; end if;
37
+      
38
+      Debut := Lst.all.Info.Num;
39
+      while aff loop
40
+	 if Lst.all.Suiv.all.Info.Num = debut then
41
+	    Aff := False;
42
+	 end if;
43
+	 Put("PID:" & Integer'Image(Lst.all.Info.Num) & ",Q=" & Integer'Image(Lst.all.Info.Dur) & "; ");
44
+	 Lst := Lst.all.Suiv;
45
+      end loop;
46
+      Put_Line("]");
47
+      New_Line;
48
+   end Afficher;
49
+   
50
+   -- Fonction de suppression d'élément 
51
+   function Del_Tache (N : Integer; Lst2 : in Liste) return Liste is
52
+      Lst : Liste := Lst2;
53
+      Prec : Liste := Lst2;
54
+   begin
55
+      while Lst.all.Info.Num /= N loop
56
+	 Lst := Lst.all.Suiv;
57
+      end loop;
58
+      while Prec.all.Suiv /= Lst loop
59
+	 Prec := Prec.all.Suiv;
60
+      end loop;
61
+      if Prec.all.Suiv = Lst.all.Suiv then
62
+	 Lst := null;
63
+	 Put_Line("Tache n°" & Integer'Image(N) & " supprimée.");
64
+      else
65
+	 Prec.all.Suiv := Lst.all.Suiv;
66
+	 Lst := Lst.all.Suiv;
67
+	 Put_Line("Tache n°" & Integer'Image(N) & " supprimée.");
68
+      end if;
69
+      return Lst;
70
+   end Del_Tache;
71
+   
72
+   
73
+   
74
+   -- fonction d'initialisation de la machine (création des taches)
75
+   function Init return Liste is
76
+      Lst : Liste := null;
77
+      P_Lst : Liste := null;
78
+   begin
79
+      Lst := new Tache'((1,3), new Tache'((2,5), new Tache'((3,2), new Tache'((4,3), null))));
80
+      P_Lst := Lst;
81
+      while P_Lst.all.suiv /= null loop
82
+	 P_Lst := P_Lst.all.Suiv;
83
+      end loop;
84
+      P_Lst.all.Suiv := Lst;
85
+      Afficher(Lst);
86
+      return Lst;
87
+   end Init;
88
+   
89
+   -- procedure de gestion des taches
90
+   procedure Processeur(Lst : in out Liste) is
91
+   begin
92
+      while Lst /= null loop
93
+	 Lst.all.Info.Dur := Lst.all.Info.Dur - Q;
94
+	 Put_Line("La tâche n°" & Integer'Image(Lst.all.Info.Num) & " est passée dans le processeur pendant un quantum.");
95
+	 
96
+	 if Lst.all.Info.Dur <= 0 then
97
+	    Put("Une tâche est terminée. ");
98
+	    Lst := Del_Tache(Lst.all.Info.Num, Lst);
99
+	    if Lst /= null then
100
+	       Lst := Lst.all.Suiv;
101
+	       --Afficher(Lst);
102
+	    end if;
103
+	 else
104
+	    Lst := Lst.all.Suiv;
105
+	    --Afficher(Lst);
106
+	 end if;
107
+      end loop;
108
+      Put_Line("La liste des tâches est vide. Fin d'éxécution.");
109
+   end Processeur;
110
+   
111
+   Lst : Liste := null;
112
+begin
113
+   Lst := Init;
114
+   Processeur(Lst);
115
+end Processeur;

BIN
semestre3/recursivite/binome/binome View File


+ 34
- 0
semestre3/recursivite/binome/binome.adb View File

@@ -0,0 +1,34 @@
1
+with Ada.Text_Io;
2
+with Ada.Command_Line; 
3
+
4
+use Ada.Command_Line;
5
+use Ada.Text_Io;
6
+
7
+procedure Binome is
8
+   
9
+   -- Fonction de calcul de coef. binomiaux
10
+   function C(P : Integer; N : Integer) return Integer is
11
+      Coef : Integer := 1;
12
+   begin
13
+      if P = 0 or N = P then
14
+	 Coef := 1;
15
+      else
16
+	 Coef := C(P-1, N-1) + C(P, N-1);
17
+      end if;
18
+      return Coef;
19
+   end C;
20
+   
21
+   -- Procédure de test de C
22
+   procedure Test_C(N : Integer) is
23
+   begin
24
+      for P in 0..N loop
25
+	 Put(Integer'Image(C(P,N)) & " ");
26
+      end loop;
27
+   end Test_C;
28
+      
29
+   
30
+begin
31
+   Test_C(Integer'Value((Argument(1))));
32
+exception
33
+   when CONSTRAINT_ERROR => Put_Line("1 argument attendu : valeur de N. Exemple : ./binome 7.");
34
+end Binome;

BIN
semestre3/recursivite/koch/koch View File


+ 57
- 0
semestre3/recursivite/koch/koch.adb View File

@@ -0,0 +1,57 @@
1
+-- Compilation possible uniquement à l'INSA
2
+with Tortue;
3
+with Ada.Text_Io;
4
+use Tortue;
5
+use Ada.Text_Io;
6
+
7
+procedure Koch is
8
+   
9
+   -- Procedure récursive pour tracer des courbes
10
+   procedure Courbe (Finesse: Integer; Longueur : Integer) is
11
+   begin
12
+      if Finesse = 1 then
13
+	 Avancer(Float(Longueur));
14
+      else 
15
+	 Courbe(Finesse - 1, Longueur / 4);
16
+	 Tourner_Gauche (60.0);
17
+	 Courbe(Finesse - 1, Longueur / 4);
18
+	 Tourner_Droite(120.0);
19
+	 Courbe(Finesse - 1, Longueur / 4);
20
+	 Tourner_Gauche(60.0);
21
+	 Courbe(Finesse - 1, Longueur / 4);
22
+      end if;
23
+   end Courbe;
24
+   
25
+   
26
+   -- Procédure pour tracer un flocon
27
+   procedure Flocon(Finesse: Integer; Longueur : Integer) is
28
+   begin
29
+      for I in 1..3 loop
30
+	 Courbe(Finesse, Longueur);
31
+	 Tourner_Droite(120.0);
32
+      end loop;
33
+   end Flocon;
34
+   
35
+
36
+   -- Initialisation de tortue
37
+   procedure Init is
38
+   begin
39
+      Ouvrir_Fenetre;
40
+      Lever_Crayon;
41
+      Aller_A(300,400);
42
+      Tourner_Droite(90.0);
43
+      Baisser_Crayon;
44
+   end Init;
45
+   
46
+   -- Procédure de test
47
+   procedure Test_Koch is
48
+      Pixel : Integer := 1000;
49
+   begin
50
+      Init;
51
+      Flocon(4, pixel);
52
+   end Test_Koch;
53
+   
54
+   
55
+begin
56
+   Test_Koch;
57
+end Koch;

BIN
semestre3/recursivite/labyrinthe/labyrinthe View File


+ 65
- 0
semestre3/recursivite/labyrinthe/labyrinthe.adb View File

@@ -0,0 +1,65 @@
1
+with Ada.Text_Io;
2
+with Ada.Integer_Text_IO;
3
+
4
+use Ada.Integer_Text_IO;
5
+use Ada.Text_IO;
6
+
7
+procedure Labyrinthe is
8
+   
9
+   type Lab is array (Integer range <>, Integer range <>) of Character;
10
+   
11
+   procedure Aff(L : Lab) is
12
+   begin
13
+      for I in L'Range(1) loop
14
+	 for J in L'Range(2) loop
15
+	    Put(L(I,J));
16
+	 end loop;
17
+	 New_Line;
18
+      end loop;
19
+      New_Line(2);
20
+   end Aff;
21
+   
22
+   procedure Trouver_Sortie(L : in out Lab; X : Integer; Y : Integer) is
23
+   begin
24
+      if L(X,Y) = 'H' then
25
+	 raise STORAGE_ERROR;
26
+      end if;
27
+      
28
+      if X = L'First or Y = L'First or X = L'Last or Y = L'Last then
29
+	 null;
30
+      else
31
+	 if L(X+1,Y) = '.' then
32
+	    Trouver_Sortie(L, X+1, Y);
33
+	 elsif L(X,Y+1) = '.' then
34
+	    Trouver_Sortie(L, X, Y+1);
35
+	 elsif L(X-1,Y) = '.' then
36
+	    Trouver_Sortie(L, X-1, Y);
37
+	 elsif L(X,Y-1) = '.' then
38
+	    Trouver_Sortie(L, X, Y-1);
39
+	 end if;
40
+      end if;
41
+      L(X,Y) := '@';
42
+      Put_Line("(" & Integer'Image(X) & "; " & Integer'Image(Y) & ")");
43
+      Aff(L);
44
+   end Trouver_Sortie;
45
+   
46
+   subtype Dim is Integer range 1..7;
47
+   Mon_Lab  : Lab (Dim,  Dim):=  (('H','H','H','H','H','H','H'),
48
+				     ('H','.','.','.','.','.','H'),
49
+				     ('H','H','H','H','.','H','H'),
50
+				     ('H','.','.','.','.','H','H'),
51
+				     ('H','.','.','H','.','H','H'),
52
+				     ('H','.','.','.','.','.','H'),
53
+				     ('H','H','H','H','H','.','H'));
54
+   Numero_Ligne_Depart,  Numero_Colonne_Depart  : Dim;
55
+   Sortie_Trouvee  : boolean  := False;
56
+begin
57
+   Aff(Mon_Lab);
58
+   put("Position  initiale : ");
59
+   get(Numero_Ligne_Depart);  
60
+   get(Numero_Colonne_Depart);
61
+   Trouver_Sortie(Mon_Lab, Numero_Ligne_Depart, Numero_Colonne_Depart);
62
+   
63
+exception
64
+   when STORAGE_ERROR => Put_Line("Le Labyrinthe n'a pas de sortie !");
65
+end Labyrinthe;

BIN
semestre3/recursivite/palindrone/palin View File


+ 51
- 0
semestre3/recursivite/palindrone/palin.adb View File

@@ -0,0 +1,51 @@
1
+with Ada.Text_Io;
2
+with Ada.Command_Line;
3
+
4
+use Ada.Command_Line;
5
+use Ada.Text_IO;
6
+
7
+procedure Palin is
8
+   
9
+   function Is_Palin(W : String) return Boolean is
10
+   begin
11
+      if W'Length <= 1 then
12
+	 return True;
13
+      else 
14
+	 if Character(W(W'First)) = Character(W(W'Last)) then
15
+	    return Is_Palin(W(W'First + 1..W'Last - 1));
16
+	 else
17
+	    return False;
18
+	 end if;
19
+      end if;
20
+   end Is_Palin;
21
+   
22
+   function Is_Palin_Ite(W : String) return Boolean is
23
+      P : Boolean := True;
24
+   begin
25
+      for I in W'First..(W'Length / 2) loop
26
+	 if (W(I..I)) /= (W(W'Last - I + 1..W'Last - I + 1
27
+			   )) then
28
+	    P := False;
29
+	 end if;
30
+      end loop;
31
+      return P;
32
+   end Is_Palin_Ite;
33
+   
34
+   
35
+begin
36
+   for I in 1..Argument_Count loop
37
+      New_Line;
38
+      Put_Line(Argument(I));
39
+      if Is_Palin(Argument(I)) then
40
+	 Put_Line("PALINDROME");
41
+      else 
42
+	 Put_Line("bin non en fait...");
43
+      end if;
44
+      
45
+      if Is_Palin_ite(Argument(I)) then
46
+	 Put_Line("PALINDROME");
47
+      else 
48
+	 Put_Line("bin non en fait...");
49
+      end if;
50
+   end loop;
51
+end Palin;

BIN
semestre3/recursivite/somme_tableau/somme View File


+ 21
- 0
semestre3/recursivite/somme_tableau/somme.adb View File

@@ -0,0 +1,21 @@
1
+with Ada.Text_Io;
2
+use Ada.Text_IO;
3
+
4
+procedure Somme is
5
+   
6
+   -- Type
7
+   type Tab is array(Integer range <>) of Float;
8
+   
9
+   function Add(T : Tab) return Float is
10
+   begin
11
+      if T'Length <= 1 then
12
+	 return T(T'Last);
13
+      else
14
+	 return T(T'First) + Add(T(T'First + 1.. T'Last));
15
+      end if;
16
+   end Add;
17
+   
18
+   T : Tab := (1.0, 1.5, 4.3);
19
+begin
20
+   Put_Line(Float'Image(Add(T)));
21
+end Somme;

BIN
semestre3/recursivite/tri/recursivite View File


+ 77
- 0
semestre3/recursivite/tri/recursivite.adb View File

@@ -0,0 +1,77 @@
1
+with Ada.Text_Io; 
2
+with Ada.Integer_Text_IO;
3
+use Ada.Text_IO;
4
+
5
+procedure Recursivite is
6
+   -- Types
7
+   type Vector is array (Integer range <>) of Integer;
8
+   
9
+   -- Fonction dichotomique de recherche
10
+   function Dichoto(V : Vector; Value : integer) return Integer is
11
+      Middle : Integer := V'First + (((V'Last)-(V'First)) / 2);
12
+      Find : Boolean := False;
13
+   begin      
14
+      --Etude des cas
15
+      if (V'Length = 2 and V(V'First) /= Middle and V(V'Last) /= Middle) or Middle = 0 then
16
+	 Middle := 0;
17
+	 return Middle;
18
+      end if;
19
+      
20
+      if Value > V(Middle) then
21
+	 declare
22
+	    V2 : Vector(Middle..V'Last) := V(Middle..V'Last);
23
+	 begin
24
+	    Middle := Dichoto(V2, Value);
25
+	 end;
26
+      elsif V(Middle) > Value then
27
+	 declare
28
+	    V2 : Vector(V'First..Middle) := V(V'First..Middle);
29
+	 begin
30
+	    Middle := Dichoto(V2, Value);
31
+	 end;
32
+      else
33
+	 null;
34
+      end if;
35
+      return Middle;
36
+   end Dichoto;
37
+   
38
+   --Procédure de test de Dichoto
39
+   procedure Test_Dichoto(V : Vector; Value : Integer) is
40
+   begin
41
+      Put_Line(" Tableau saisie : ");
42
+      for I in V'Range loop
43
+	 Put(Integer'Image(V(I)) & "  ");
44
+      end loop;
45
+      New_Line;
46
+      Put_Line("Valeur recherchée : " & Integer'Image(Value));
47
+      if Dichoto(V, Value) /= 0 then
48
+	 Put_Line("Valeur trouvée : " & Integer'Image(V(Dichoto(V, Value))));
49
+      else 
50
+	 Put_Line("La valeur n'existe pas dans le tableau");
51
+      end if;
52
+   end Test_Dichoto;
53
+   
54
+   -- Fonction factorielle récursive
55
+   function Factorielle(N : Integer) return Integer is
56
+      Resultat : Integer;
57
+   begin
58
+      if N = 0 then
59
+	 Resultat := 1;
60
+      else
61
+	 Resultat := N* Factorielle(N-1);
62
+      end if;
63
+      return Resultat;
64
+   end Factorielle;
65
+   
66
+   V1 : Vector(1..20) := (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
67
+   V2 : Vector(1..20) := (11,29,30,46,56,64,71,89,98,107,110,123,133,145,150,168,171,189,193,210);
68
+   N : Integer;
69
+begin
70
+   Test_Dichoto(V1, 16);
71
+   Test_Dichoto(V2, 56);
72
+   Test_Dichoto(V2, 31);
73
+   
74
+   Put("Factorielle de : ");
75
+   Ada.Integer_Text_IO.Get(N);
76
+   Put_Line(Integer'Image(Factorielle(N)));
77
+end Recursivite;

+ 11
- 0
semestre4/TP1_piles/afficher_test.adb View File

@@ -0,0 +1,11 @@
1
+with Ada.Text_Io;
2
+
3
+procedure Afficher_Test(Objet_du_Test, Attendu, Obtenu : in  String) is
4
+begin
5
+   Ada.Text_Io.New_Line;
6
+   Ada.Text_Io.Put_Line("-----------------------------------------------------------");
7
+   Ada.Text_Io.Put_Line(Objet_du_Test);
8
+   Ada.Text_Io.Put_Line("Resultat attendu : " & Attendu);
9
+   Ada.Text_Io.Put_Line("Resultat obtenu  : " & Obtenu);
10
+   Ada.Text_Io.New_Line;
11
+end Afficher_Test;

+ 1
- 0
semestre4/TP1_piles/afficher_test.ads View File

@@ -0,0 +1 @@
1
+procedure Afficher_Test(Objet_du_Test, Attendu, Obtenu : in  String);

+ 145
- 0
semestre4/TP1_piles/piles_entiers.adb View File

@@ -0,0 +1,145 @@
1
+-- Auteurs : P. E.
2
+-- Version du 30/01/2019
3
+
4
+-- Sous-programmes à compléter
5
+-- Init_Pile
6
+-- Est_Vide
7
+-- Sommet
8
+-- Empiler
9
+-- Depiler
10
+-- Hauteur
11
+-- Liste_To_String
12
+-- To_String
13
+
14
+with Unchecked_Deallocation;
15
+with Ada.Text_Io; use Ada.Text_Io;
16
+
17
+package body Piles_Entiers is
18
+
19
+   procedure Free is new Unchecked_Deallocation(Cellule, Liste);
20
+   -- Desallocation d'une Cellule pointee par un pointeur de type Liste
21
+   -- Procedure utilisee lors des operations Depiler(P) et Vider(P)
22
+   
23
+   procedure Vide_Liste(L : in out Liste) is
24
+   begin
25
+      if L /= null then
26
+	 Vide_Liste(L.all.Suiv);
27
+	 Free(L.all.Suiv);
28
+      end if;
29
+   end Vide_Liste;
30
+
31
+   procedure Init(P : in out Pile) is
32
+   -- Ne fait rien si P est deja vide a l'appel
33
+   -- Sinon efface tous les elements de P (en
34
+   -- recuperant la memoire allouee)
35
+   -- et retourne la pile vide
36
+   begin
37
+      Vide_Liste(P.Debut);
38
+      Free(P.Debut);
39
+   end Init;
40
+   
41
+   function Est_Vide(P : in Pile) return Boolean is
42
+   -- Retourne vrai si la pile est vide, faux sinon
43
+   begin
44
+      return (P.Debut = null);
45
+   end Est_Vide;
46
+
47
+   function Sommet(P : in Pile) return Integer is
48
+   -- Retourne le premier element de P (situe au sommet)
49
+   begin
50
+      if Est_Vide(P) then
51
+	 raise Pile_Vide;
52
+      end if;
53
+      return P.Debut.all.info;
54
+   end Sommet;
55
+
56
+   procedure Empiler(E : in Integer; P : in out Pile) is
57
+   -- Empile E au dessus de P ; E devient le nouveau sommet
58
+   begin
59
+      P.Debut := new Cellule'(E, P.Debut);
60
+      P.Hauteur := P.Hauteur + 1;
61
+   end Empiler;
62
+
63
+   procedure Depiler(P: in out Pile) is
64
+   -- Efface le sommet de P ; attention, penser a recuperer
65
+   -- la memoire associee a la cellule a effacer
66
+      Buffer : Liste;
67
+   begin
68
+      if Est_Vide(P) then
69
+	 raise Pile_Vide;
70
+      end if;
71
+      Buffer := P.Debut;
72
+      P.Debut := P.Debut.all.Suiv;
73
+      Free(Buffer);
74
+      P.Hauteur := P.Hauteur - 1;
75
+   exception
76
+      when Pile_Vide => Put_Line("Tentative de pull une liste vide !");
77
+   end Depiler;
78
+
79
+   function Hauteur(P : in Pile) return Natural is
80
+   -- Calculer la hauteur en comptant le nombre d'elements depilables
81
+   -- n'est pas efficace. Cette fonction retourne directement le champ
82
+   -- hauteur du record associe a une pile
83
+   begin
84
+      return P.Hauteur;
85
+   end Hauteur;
86
+
87
+   function Liste_To_String(L : Liste) return String is
88
+   -- Convertit une liste d'entiers en une chaine de caracteres
89
+   begin
90
+      if L /= null then
91
+	 return Integer'Image(L.all.Info) & " - " & Liste_To_String(L.all.Suiv);
92
+      else
93
+	 return ";";
94
+      end if;
95
+   end Liste_To_String;
96
+
97
+   function To_String(P : in Pile) return String is
98
+   -- Convertit une pile d'entiers en une chaine de caracteres
99
+   begin
100
+      return Liste_To_String(P.Debut);   
101
+   end To_String;
102
+
103
+   function "="(P1,P2 : in Pile) return Boolean is
104
+      -- Verifie que les piles sont identiques (memes elements et meme ordre)
105
+      L, L2 : Liste;
106
+      Egal : Boolean := true;
107
+   begin
108
+      L := P1.Debut;
109
+      L2 := P2.Debut;
110
+      while L /= null and L2 /= null and Egal = True loop
111
+	 if L.all.Info /= L2.all.info then
112
+	    Egal := False;
113
+	 end if;
114
+	 L := L.all.Suiv;
115
+	 L2 := L2.all.Suiv;
116
+      end loop;
117
+      if L /= null or L2 /= null then
118
+	 Egal := False;
119
+      end if;
120
+      return Egal;
121
+   end "=";
122
+
123
+
124
+
125
+
126
+
127
+--   procedure Free_Liste(L : in out Liste) is
128
+--   -- Desallocation de toutes les Cellules d'une Liste
129
+--   begin
130
+--      if L /= null then
131
+--         Free_Liste(L.All.Suiv);  -- desallocation de la liste suivante PUIS
132
+--         Free(L);                 -- desallocation de le premiere cellule
133
+--      end if;
134
+--      L := null;                  -- en principe c'est le cas apres Free(L)
135
+--   end Free_Liste;
136
+
137
+--   procedure Vider(P : in out Pile) is   -- pas indispensable pour le paquetage
138
+--   begin
139
+--                        --A COMPLETER EVENTUELLEMENT (reutiliser Free_Liste)
140
+--   end Vider;
141
+
142
+end Piles_Entiers;
143
+
144
+
145
+

+ 63
- 0
semestre4/TP1_piles/piles_entiers.ads View File

@@ -0,0 +1,63 @@
1
+-- Auteurs : P. E.
2
+-- Version du 30/01/2019
3
+
4
+package Piles_Entiers is
5
+
6
+   type Pile is limited private;
7
+
8
+   Pile_Vide : exception;
9
+   -- exception levee si on tente d'acceder au sommet d'une pile vide
10
+   -- ou si on tente de depiler une pile vide.
11
+
12
+   -- ****************************************
13
+   -- OPERATIONS INDISPENSABLES DU T.A.D. PILE
14
+   -- ****************************************
15
+
16
+   procedure Init(P : in out Pile);
17
+   -- Ne fait rien si P est deja vide a l'appel
18
+   -- Sinon efface tous les elements de P (en
19
+   -- recuperant la memoire allouee)
20
+   -- et retourne la pile vide
21
+
22
+   function  Est_Vide(P : in Pile) return Boolean;
23
+   -- Retourne vrai si la pile est vide, faux sinon
24
+
25
+   function  Sommet(P : in Pile) return Integer;
26
+   -- Retourne le premier element de P (situe au sommet)
27
+
28
+   procedure Empiler(E : in Integer; P : in out Pile);
29
+   -- Empile E au dessus de P ; E devient le nouveau sommet
30
+
31
+   procedure Depiler(P: in out Pile);
32
+   -- Efface le sommet de P ; attention, penser a recuperer
33
+   -- la memoire associee a la cellule a effacer
34
+
35
+   -- **************************************
36
+   -- OPERATIONS FACULTATIVES DU T.A.D. PILE
37
+   -- **************************************
38
+
39
+   function Hauteur(P : in Pile) return Natural;
40
+   -- Calculer la hauteur en comptant le nombre d'elements depilables
41
+   -- n'est pas efficace. Cette fonction accede directement au champ
42
+   -- hauteur du record associe a une pile
43
+
44
+   function To_String(P : in Pile) return String;
45
+   -- Convertit une pile d'entiers en une chaine de caracteres
46
+
47
+   function "="(P1,P2 : in Pile) return boolean;
48
+   -- Verifie que les piles sont identiques (memes elements et meme ordre)
49
+
50
+private
51
+   type Cellule;
52
+   type Liste   is access Cellule;
53
+   type Cellule is record
54
+        Info : Integer;
55
+        Suiv : Liste;
56
+   end record;
57
+
58
+   type Pile is record
59
+        Debut  : Liste   := null;
60
+        Hauteur: Natural := 0;
61
+   end record;
62
+
63
+end Piles_Entiers;

BIN
semestre4/TP1_piles/post_fixee View File


+ 134
- 0
semestre4/TP1_piles/post_fixee.adb View File

@@ -0,0 +1,134 @@
1
+with Ada.Text_Io, Piles_Entiers, Afficher_Test;
2
+use  Ada.Text_Io, Piles_Entiers;
3
+
4
+procedure Post_Fixee is
5
+   
6
+   type Tab is array (Character range 'A'..'Z') of Integer;
7
+   
8
+   Symbole_Inconnu : exception;
9
+   Manque_Operande : exception;
10
+   Manque_Operateur : exception;
11
+   
12
+   procedure Lire_Entree(E : in out String; T : in out Tab) is 
13
+      Len : Integer := 0;
14
+   begin
15
+      Get_Line(E, len);
16
+      for I in Len+1..E'Last loop
17
+	 E(I) := ' ';
18
+      end loop;
19
+      
20
+      for J in 1..Len loop
21
+	 case E(J) is
22
+	    when 'A'..'Z' => 
23
+	       Put("Quelle est la valeur de " & Character'Image(E(J)) & " ?");
24
+	       T(E(J)) := Integer'Value(Get_line);
25
+	    when others => null;
26
+	 end case;
27
+      end loop;
28
+      
29
+   end Lire_Entree;
30
+   
31
+   procedure Chk(P : in out Pile) is
32
+   begin
33
+      if Hauteur(P) < 2 then 
34
+	 raise Manque_Operande;
35
+      end if;
36
+   end Chk;
37
+   
38
+   
39
+   procedure Somme(P : in out Pile) is
40
+      A,B : Integer;
41
+   begin
42
+      Chk(P);
43
+      A := Sommet(P);
44
+      Depiler(P);
45
+      B := Sommet(P);
46
+      Depiler(P);
47
+      Empiler(A+B, P);
48
+   end Somme;
49
+   
50
+   procedure Souss(P : in out Pile) is
51
+      A,B : Integer;
52
+   begin
53
+      Chk(P);
54
+      A := Sommet(P);
55
+      Depiler(P);
56
+      B := Sommet(P);
57
+      Depiler(P);
58
+      Empiler(B-A, P);
59
+   end Souss;
60
+
61
+   procedure Mult(P : in out Pile) is
62
+      A,B : Integer;
63
+   begin
64
+      Chk(P);
65
+      A := Sommet(P);
66
+      Depiler(P);
67
+      B := Sommet(P);
68
+      Depiler(P);
69
+      Empiler(A*B, P);
70
+   end Mult;
71
+   
72
+   procedure Div(P : in out Pile) is 
73
+      A,B : Integer;
74
+   begin
75
+      Chk(P);
76
+      A := Sommet(P);
77
+      Depiler(P);
78
+      B := Sommet(P);
79
+      Depiler(P);
80
+      Empiler(B/A, P);
81
+   end Div;
82
+   
83
+   function Eval_Exp_PostFixee(E : String; T : Tab) return Integer is
84
+      P : Pile;
85
+   begin
86
+      Init(P);
87
+      Put_Line(E);
88
+      for I in E'First..E'Last loop
89
+	 case E(I) is
90
+	    when 'A'..'Z' => Empiler(T(E(I)), P);
91
+	    when '+' => Somme(P);
92
+	    when '-' => Souss(P);
93
+	    when '*' => Mult(P);
94
+	    when '/' => Div(P);
95
+	    when ' ' => null;
96
+	    when others => raise Symbole_Inconnu;
97
+	 end case;
98
+      end loop;
99
+      
100
+      if Hauteur(P) /= 1 then
101
+	 raise Manque_Operateur;
102
+      end if;
103
+      
104
+      return Sommet(P);
105
+   end Eval_Exp_PostFixee;
106
+   
107
+   procedure display is
108
+      E : String(1..20);
109
+      Len : Integer := 0;
110
+      T : Tab;
111
+   begin
112
+      for I in T'Range loop
113
+	 T(I) := Len;
114
+	 Len := Len + 1;
115
+	 --Put_Line(I & " : " & Integer'Image(T(I)));
116
+      end loop;
117
+      
118
+      Put_Line("Saisir l'expression : ");
119
+      Lire_Entree(E, T);
120
+      
121
+      Put_Line(Integer'Image(Eval_Exp_PostFixee(E, T)));
122
+      
123
+   exception
124
+      when Symbole_Inconnu => Put_Line("Un des caractères saisis est non valide."); Display;
125
+      when Manque_Operande => Put_Line("Le nombre d'opérandes n'est pas valide."); Display;
126
+      when Manque_Operateur => Put_Line("Le nombre d'opérateurs n'est pas valide."); Display;
127
+   end Display;
128
+   
129
+   
130
+begin
131
+   <<Entry0>>
132
+   Put_Line("Programme d'interprétation de chaine de calcul postfixee : "); 
133
+   Display;
134
+end Post_Fixee;

BIN
semestre4/TP1_piles/tests_piles_entiers View File


+ 107
- 0
semestre4/TP1_piles/tests_piles_entiers.adb View File

@@ -0,0 +1,107 @@
1
+-- Auteurs : P. E.
2
+-- Version du 30/01/2019
3
+
4
+with Ada.Text_Io, Piles_Entiers, Afficher_Test;
5
+use  Ada.Text_Io, Piles_Entiers;
6
+
7
+procedure Tests_Piles_Entiers is
8
+begin
9
+   ---------------------------------------------------------
10
+   -- 1. Tests apres la declaration et acces a une pile vide
11
+   ---------------------------------------------------------
12
+   Put_Line("Test 1 : apres Declaration d'une pile P");
13
+   declare
14
+      P : Pile;
15
+   begin
16
+      Afficher_Test("Est_Vide(P)  ?", "TRUE", Boolean'Image(Est_Vide(P)));
17
+      Afficher_Test("Hauteur(P)   ?", "0   ", Integer'Image(Hauteur(P)));
18
+      Afficher_Test("To_String(P) ?", "    ", To_String(P));
19
+   end;
20
+   New_Line;
21
+   Put_Line("Test 2: Tentative d'acces au sommet d'une pile vide");
22
+   declare
23
+      P  : Pile;
24
+      Nb : Integer;
25
+   begin
26
+      Nb := Sommet(P);
27
+      Afficher_Test("Sommet(P)  ?", "levee exception", Integer'Image(Nb));
28
+      Put_Line("bizarre ... l'exception n'a pas ete levee ... ");
29
+   exception
30
+      when Pile_Vide =>
31
+      Put_Line("ok, l'exception Pile_Vide a ete levee !!");
32
+   end;
33
+
34
+	---------------------
35
+	-- 2. Tests d'empiler
36
+	---------------------
37
+   declare
38
+      P : Pile;
39
+   begin
40
+      New_Line;
41
+      Put_Line("Test 3 : Empiler 10 entiers ");
42
+      for I in 2..12 loop
43
+	 Empiler(I, P);
44
+      end loop;
45
+      Put_Line(To_String(P));
46
+   end;
47
+
48
+	--------------------------------
49
+	-- 3. Tests de Depiler et Sommet
50
+	--------------------------------
51
+   declare
52
+      P  : Pile;
53
+      Nb : Integer;
54
+   begin
55
+      -- Empiler 10 elements
56
+      Init(P);
57
+      for I in 1..10 loop
58
+	 Empiler(I, P);
59
+      end loop;
60
+      New_Line;
61
+      Put_Line("Test 4: Affichage du sommet et depilement pendant 10 fois ...");
62
+
63
+      -- Verifier que la pile est bien vide apres 10 appels a Depiler
64
+      for J in 1..10 loop
65
+	 Depiler(P);
66
+      end loop;
67
+      if Est_Vide(P) then
68
+	 Put_Line("La pile est vide");
69
+      else
70
+	 Put_Line("TEST 4 FAUTIF");
71
+	 --raise PROGRAM_ERROR;
72
+      end if;
73
+      New_Line;
74
+      Put_Line("Test 5: Tentative de depilement d'une pile vide ...");
75
+      Init(P);
76
+      Depiler(P);
77
+      end;
78
+
79
+	-----------------------------------
80
+	-- 4. Test sur l'egalite de 2 piles
81
+	-----------------------------------
82
+   Put_Line("Test 6 : Initialisation de 2 piles P1 et P2, et comparaison, ajout de 10 elements et comparaison");
83
+   declare
84
+      P1, P2 : Pile;
85
+   begin
86
+      null;
87
+      -- P1 et P2 viennent d'etre declarees, elles sont donc vides
88
+      -- Verifier qu'elles sont identiques (P1=P2)
89
+      New_Line;
90
+      Put_Line("Test 6 : Deux piles vides sont-elles identiques ?");
91
+      if P1 = P2 then
92
+	 Put_Line("Elles sont identiques");
93
+      end if;
94
+      New_Line;
95
+      Put_line("On empile desormais 10 entiers 1..10 sur les 2 piles");
96
+      for I in 2..11 loop
97
+	 Empiler(I, P1);
98
+	 Empiler(I, P2);
99
+	 Put_Line("On empile sur P1 et P2 : " & Integer'Image(I));
100
+      end loop;
101
+      New_Line;
102
+      Put_Line("Test 7 : Deux piles contenant 1..10 sont-elles identiques ?");
103
+      if P1 = P2 then
104
+	 Put_Line("Identiques");
105
+      end if;
106
+   end;
107
+end Tests_Piles_Entiers;

+ 11
- 0
semestre4/TP2_listes_ordonnees_type_LP/afficher_test.adb View File

@@ -0,0 +1,11 @@
1
+with Ada.Text_Io;
2
+
3
+procedure Afficher_Test(Objet_du_Test, Attendu, Obtenu : in  String) is
4
+begin
5
+   Ada.Text_Io.New_Line;
6
+   Ada.Text_Io.Put_Line("-----------------------------------------------------------");
7
+   Ada.Text_Io.Put_Line(Objet_du_Test);
8
+   Ada.Text_Io.Put_Line("Resultat attendu : " & Attendu);
9
+   Ada.Text_Io.Put_Line("Resultat obtenu  : " & Obtenu);
10
+   Ada.Text_Io.New_Line;
11
+end Afficher_Test;

+ 151
- 0
semestre4/TP2_listes_ordonnees_type_LP/listes_ordonnees_entiers.adb View File

@@ -0,0 +1,151 @@
1
+with Ada.Unchecked_Deallocation;
2
+
3
+package body Listes_Ordonnees_Entiers is
4
+
5
+   -------------------------------------------------------------------------
6
+   function Est_Vide(L : in Une_Liste_Ordonnee_Entiers) return Boolean is
7
+   begin
8
+      return L.Debut = null;
9
+   end Est_Vide;
10
+   -------------------------------------------------------------------------
11
+
12
+   -------------------------------------------------------------------------
13
+   function Cardinal(L : in Une_Liste_Ordonnee_Entiers) return Integer is
14
+   begin
15
+      return L.Taille;
16
+   end Cardinal;
17
+   -------------------------------------------------------------------------
18
+
19
+   -----------------------------------------------------------------------------
20
+   -- Appartient classique sur une liste simplement chainee (type Lien) ordonnee
21
+
22
+   function Appartient_Lien(E : Integer; LL : in Lien) return Boolean is
23
+      Resultat :boolean;
24
+   begin
25
+      if LL = null or else E < LL.all.info then
26
+         Resultat := False;         -- element non trouve
27
+      elsif LL.all.Info = E then
28
+         Resultat := True;          -- element trouve en 1ere place
29
+      else
30
+         Resultat := Appartient_Lien(E, LL.all.Suiv);  -- on cherche plus loin
31
+      end if;
32
+      return Resultat;
33
+   end Appartient_Lien;
34
+
35
+   -- Appartient sur le type Une_Liste_Ordonnee_Entiers
36
+   -- On reutilise la fonction classique Appartient_Lien sur L.debut
37
+   function Appartient(E : in integer; L : in Une_Liste_Ordonnee_Entiers) return Boolean is
38
+   begin
39
+      return Appartient_Lien(E, L.Debut);
40
+   end Appartient;
41
+   -------------------------------------------------------------------------
42
+
43
+   -------------------------------------------------------------------------
44
+   -- Conversion en chaine de caracteres
45
+   --
46
+   -- sur le type Lien
47
+
48
+   function Lien_To_String(LL : in Lien) return String is
49
+   begin
50
+      if LL = null then return "";
51
+                   else return integer'image(LL.all.info) & Lien_To_String(LL.all.suiv);
52
+      end if;
53
+   end Lien_To_String;
54
+
55
+   -- sur le type Une_Liste_Ordonnee_Entiers
56
+   function Liste_To_String(L: in Une_Liste_Ordonnee_Entiers) return String is
57
+   begin
58
+      return Integer'Image(L.Taille) & " elements : (" & Lien_To_String(L.Debut) & " )";
59
+   end Liste_To_String;
60
+   -------------------------------------------------------------------------
61
+
62
+   -------------------------------------------------------------------------
63
+   -- Insertion ORDONNEE et SANS DOUBLON
64
+   
65
+   procedure Inserer_Lien(E: in Integer; L: in out Lien) is
66
+   begin
67
+      if L = null then
68
+	 L := new Cellule'(E, null);
69
+      elsif L.Info = E then raise Element_Deja_Present;
70
+      elsif L.info > E then
71
+	 L := new Cellule'(E, L);
72
+      else
73
+	 Inserer_Lien(E, L.Suiv);
74
+      end if;
75
+
76
+   -- On desire une version RECURSIVE
77
+   -- La procedure doit LEVER L'EXCEPTION Element_Deja_Present en
78
+   -- cas de tentative d'insertion d'un doublon
79
+   end Inserer_Lien;
80
+
81
+
82
+
83
+   -------------------------------------------------------------------------
84
+   procedure Inserer(E: in integer; L: in out Une_Liste_Ordonnee_Entiers) is
85
+   begin
86
+      Inserer_Lien(E, L.Debut);
87
+      L.Taille := L.Taille + 1;
88
+   end Inserer;
89
+   -------------------------------------------------------------------------
90
+
91
+
92
+   -- Instanciation de Ada.Unchecked_Deallocation pour desallouer
93
+   -- la memoire en cas de suppression des elements d'une liste
94
+   -------------------------------------------------------------------------
95
+   procedure Free is new Ada.Unchecked_Deallocation(Cellule, Lien);
96
+   -------------------------------------------------------------------------
97
+   procedure Supprimer_Lien(E : in Integer; L: in out Lien) is
98
+      Recup : Lien;
99
+   begin
100
+      if L = null or else E < L.All.Info then
101
+         raise Element_Non_Present;
102
+      elsif E = L.All.Info then
103
+         Recup := L;           -- on repere la cellule a recycler
104
+         L     := L.All.Suiv;  -- on modifie le debut de la liste
105
+         Free(Recup);          -- on recupere la memoire
106
+      else
107
+         Supprimer_Lien(E, L.all.suiv);
108
+      end if;
109
+   end Supprimer_Lien;
110
+   -------------------------------------------------------------------------
111
+   procedure Supprimer(E: in integer; L: in out Une_Liste_Ordonnee_Entiers) is
112
+   begin
113
+      Supprimer_Lien(E, L.debut);
114
+      L.Taille := L.Taille - 1;
115
+   end Supprimer;
116
+   -------------------------------------------------------------------------
117
+   
118
+   -------------------------------------------------------------------------
119
+   -- Fonctions facultatives
120
+   function Egal_Lien(L1, L2 : in Lien) return Boolean is
121
+   begin
122
+      if L1 = null and L2 = null then
123
+	 return True;
124
+      elsif (L1 = null or L2 = null) or (L1.Info /= L2.Info) then
125
+	 return False;
126
+      elsif L1.Info = L2.Info then
127
+	 return Egal_Lien(L1.all.Suiv, L2.all.Suiv);
128
+      else
129
+	 return FALSE; -- Ligne de code jamais atteinte, mais supprime des messages d'erreurs à la compilation.
130
+      end if;
131
+   end Egal_Lien;
132
+   
133
+   function "="(L1, L2 : in Une_Liste_Ordonnee_Entiers) return Boolean is
134
+   begin
135
+      return Egal_Lien(L1.Debut, L2.Debut);
136
+   end "=";
137
+   
138
+   function Copie_Lien(L1: in Lien) return Lien is
139
+   begin
140
+      if L1 = null then return null;
141
+      else return new Cellule'(L1.all.Info, Copie_Lien(L1.all.Suiv)); 
142
+      end if; 
143
+   end Copie_Lien;
144
+   
145
+   procedure Copie(L1 : in Une_Liste_Ordonnee_Entiers; L2 : out Une_Liste_Ordonnee_Entiers) is
146
+   begin
147
+      L2.Debut := Copie_lien(L1.Debut);
148
+      L2.Taille := L1.Taille;
149
+   end Copie;
150
+   
151
+end Listes_Ordonnees_Entiers;

+ 41
- 0
semestre4/TP2_listes_ordonnees_type_LP/listes_ordonnees_entiers.ads View File

@@ -0,0 +1,41 @@
1
+package Listes_Ordonnees_Entiers is
2
+
3
+   type Une_Liste_Ordonnee_Entiers is limited private;
4
+
5
+   Element_Non_Present, Element_Deja_Present : exception;
6
+
7
+   function Est_Vide(L : in Une_Liste_Ordonnee_Entiers) return Boolean;
8
+
9
+   function Cardinal(L : in Une_Liste_Ordonnee_Entiers) return Integer;
10
+
11
+   function Appartient(E : in integer; L : in Une_Liste_Ordonnee_Entiers) return Boolean;
12
+
13
+   procedure Inserer(E: in integer; L: in out Une_Liste_Ordonnee_Entiers);
14
+
15
+   procedure Supprimer(E: in integer; L: in out Une_Liste_Ordonnee_Entiers);
16
+
17
+   function Liste_To_String(L: in Une_Liste_Ordonnee_Entiers) return String;
18
+
19
+   --ajouts de ss-programmes d'egalite et de copie
20
+   function "="(L1, L2 : in Une_Liste_Ordonnee_Entiers) return Boolean;
21
+
22
+   procedure Copie(L1 : in Une_Liste_Ordonnee_Entiers; L2 : out Une_Liste_Ordonnee_Entiers);
23
+
24
+
25
+private
26
+   -- types classiques permettant de realiser des listes simplement chainees
27
+   type Cellule;
28
+   type Lien    is access Cellule;
29
+   type Cellule is record
30
+        Info : integer;
31
+        Suiv : Lien;
32
+   end record;
33
+
34
+   -- type liste ameliore : record contenant la liste et sa taille
35
+   -- (evite de parcourir la liste pour calculer la taille)
36
+
37
+   type Une_Liste_Ordonnee_Entiers is record
38
+      Debut  : Lien    := null;
39
+      Taille : Natural := 0;
40
+   end record;
41
+end Listes_Ordonnees_Entiers;

BIN
semestre4/TP2_listes_ordonnees_type_LP/mon_application View File


+ 39
- 0
semestre4/TP2_listes_ordonnees_type_LP/mon_application.adb View File

@@ -0,0 +1,39 @@
1
+with Listes_Ordonnees_Entiers;         use Listes_Ordonnees_Entiers;
2
+with Ada.Text_Io;                      use Ada.Text_Io;
3
+with Afficher_Test;
4
+
5
+procedure Mon_Application is
6
+   L1, L2 : Une_Liste_Ordonnee_Entiers;
7
+begin
8
+   Put_Line("-----------------------------------------------------------");
9
+   Put_Line("Etape 1 : Insertion d'elements dans L1");
10
+   Inserer(3, L1);
11
+   Inserer(5, L1);
12
+   Inserer(4, L1);
13
+   Inserer(2, L1);
14
+   Put_Line("Contenu de L1 : " & Liste_To_String(L1));
15
+
16
+   Put_Line("-----------------------------------------------------------");
17
+   Put_Line("Etape 2 - Affectation de L1 a L2");
18
+
19
+   Copie(L1, L2);
20
+   Put_Line("Contenu de L2 : " & Liste_To_String(L2));
21
+
22
+   Put_Line("-----------------------------------------------------------");
23
+   Put_Line("Etape 3 - Ajout de 1 a L1 et de 1 a L2");
24
+   Inserer(1, L1);
25
+   Inserer(1, L2);
26
+   Put_Line("Contenu de L1 : " & Liste_To_String(L1));
27
+   Put_Line("Contenu de L2 : " & Liste_To_String(L2));
28
+
29
+   -- Les deux listes sont-elle egales ?
30
+   Afficher_Test("L1 = L2 ?", "TRUE", Boolean'Image(L1=L2));
31
+
32
+   Put_Line("-----------------------------------------------------------");
33
+   Put_Line("Etape 4 - Ajouts de 2 elements 0 et 6 a L1");
34
+   Inserer(0, L1);
35
+   Inserer(6, L1);
36
+   Put_Line("Contenu de L1 : " & Liste_To_String(L1));
37
+   Put_Line("Contenu de L2 : " & Liste_To_String(L2));
38
+
39
+end Mon_Application;

BIN
semestre4/TP2_listes_ordonnees_type_LP/test_listes_ordonnees_entiers View File


+ 110
- 0
semestre4/TP2_listes_ordonnees_type_LP/test_listes_ordonnees_entiers.adb View File

@@ -0,0 +1,110 @@
1
+with Ada.Text_Io, listes_ordonnees_entiers, Afficher_Test;
2
+use  Ada.Text_Io, listes_ordonnees_entiers;
3
+
4
+procedure Test_Listes_Ordonnees_Entiers is
5
+begin
6
+   -----------------------------------------------------------
7
+   -- Test de création
8
+   -----------------------------------------------------------
9
+   Put_Line("Test après création");
10
+   declare
11
+      L : Une_Liste_Ordonnee_Entiers;
12
+   begin
13
+      Afficher_Test("Est_Vide() ?", "TRUE", Boolean'Image(Est_Vide(L)));
14
+      Afficher_Test("Cardinal() ?", "0", Integer'Image(Cardinal(L)));
15
+      
16
+      Put_Line("Test d'affichage: ");
17
+      Put_Line(Liste_To_String(L)); New_Line;
18
+   end;
19
+   -----------------------------------------------------------
20
+   
21
+   
22
+   -----------------------------------------------------------
23
+   -- Test d'ajout d'éléments
24
+   -----------------------------------------------------------
25
+   Put_Line("Test après ajout d'éléments");
26
+   declare
27
+       L : Une_Liste_Ordonnee_Entiers;
28
+   begin
29
+      Put_Line("Liste créée, on ajout des éléments");
30
+      Inserer(1,L);
31
+      Inserer(-1,L);
32
+      Inserer(3,L);
33
+      Inserer(45,L);
34
+      Inserer(2,L);
35
+      Inserer(9,L);
36
+      Put_Line("6 éléments ajoutés : [1, -1, 3, 45, 2, 9].");
37
+      
38
+      Put_Line("Test d'affichage: ");
39
+      Put_Line(Liste_To_String(L)); New_Line;
40
+      
41
+      Afficher_Test("Est_Vide() ?", "FALSE", Boolean'Image(Est_Vide(L)));
42
+      Afficher_Test("Cardinal() ?", "6", Integer'Image(Cardinal(L)));
43
+      Afficher_Test("Appartient(2) ?", "TRUE", Boolean'Image(Appartient(2,L)));
44
+   end;
45
+   -----------------------------------------------------------
46
+   
47
+   
48
+   -----------------------------------------------------------
49
+   -- Test de manipulation
50
+   -----------------------------------------------------------
51
+   Put_Line("Test de manipulation");
52
+   declare
53
+      L : Une_Liste_Ordonnee_Entiers;
54
+   begin
55
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);Inserer(45,L);Inserer(2,L);Inserer(9,L);
56
+      Put_Line("Liste créée, 6 éléments ajoutés : [1, -1, 3, 45, 2, 9].");
57
+      Put_Line("Liste: ");
58
+      Put_Line(Liste_To_String(L)); New_Line;
59
+      Put_Line("On supprime 2:"); Supprimer(2,L);
60
+      Afficher_Test("Cardinal() ?", "5", Integer'Image(Cardinal(L)));
61
+      Afficher_Test("Appartient(2) ?", "FALSE", Boolean'Image(Appartient(2,L)));
62
+   end;
63
+   -----------------------------------------------------------
64
+   
65
+   
66
+   -----------------------------------------------------------
67
+   -- Test d'exceptions
68
+   -----------------------------------------------------------
69
+   declare
70
+      L : Une_Liste_Ordonnee_Entiers;
71
+   begin
72
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);
73
+      Put_Line("On supprime un élément inexistant : ");
74
+      Supprimer(28, L);
75
+   exception
76
+      when Element_Non_Present => Put_Line("L'exception Element_Non_Present est correctement levée !");
77
+   end;
78
+   declare
79
+      L : Une_Liste_Ordonnee_Entiers;
80
+   begin
81
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);
82
+      Put_Line("On ajoute un élément déjà présent : ");
83
+      Inserer(1, L);
84
+   exception
85
+      when Element_Deja_Present => Put_Line("L'exception Element_Deja_Present est correctement levée !");
86
+   end;
87
+   -----------------------------------------------------------
88
+   
89
+   
90
+   -----------------------------------------------------------
91
+   -- Test des fonctions auxiliaires
92
+   -----------------------------------------------------------
93
+   declare
94
+       L, L2 : Une_Liste_Ordonnee_Entiers;
95
+   begin
96
+      Put_Line("On créé une liste L: ");
97
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);
98
+      Put_Line(Liste_To_String(L)); New_Line;
99
+      Put_Line("On en créé une copie L2: ");
100
+      Copie(L, L2);
101
+      Put_Line(Liste_To_String(L2)); New_Line;
102
+      
103
+      Put_Line("On vérifie qu'elles sont égales:");
104
+      Afficher_Test("=(L,L2) ?", "TRUE", Boolean'Image(L=L2));
105
+   end;
106
+   -----------------------------------------------------------
107
+   
108
+   New_Line;
109
+   Put_Line("Fin des tests.");
110
+end Test_Listes_Ordonnees_Entiers;

+ 10
- 0
semestre4/TP3_paquetages_generiques/2015-02-16_11-34-06_Annuaire_10.txt View File

@@ -0,0 +1,10 @@
1
+Charles Chang Beziers ORL 0703888032
2
+Martha Bibbs Beauvais Psychiatre 0616751216
3
+Jerry Joosten Albi Pharmacien 0724258260
4
+Elijah Taylor Caen Orthodontiste 0770222606
5
+Gary Maupin Bayonne Rhumatologue 0705071875
6
+William Snider Tours Radiologue 0621112196
7
+Josefa Eckel Villeurbanne Kinesitherapeute 0784142335
8
+John Brunton Lorient Oncologue 0617519421
9
+Ronald Crank Montreuil Dentiste 0668920050
10
+Joanne Ramos Sevran Veterinaire 0657148529

+ 100
- 0
semestre4/TP3_paquetages_generiques/2015-02-16_11-35-09_Annuaire_100.txt View File

@@ -0,0 +1,100 @@
1
+Christina Salvietti Dunkerque Stomatologue 0614557340
2
+Thomas Dalton Orleans Rhumatologue 0717045284
3
+Michael Hemp Pantin Psychiatre 0789751830
4
+Christopher Chalmers Suresnes Veterinaire 0765856048
5
+Kathrine Hall Tours Radiologue 0723029341
6
+Robin Cook Angers Dermatologue 0771690567
7
+Alexander Seaberry Versailles Veterinaire 0688468848
8
+Lydia Gunter Montrouge Radiologue 0791786318
9
+Ronald Berry Pantin Urologue 0766359222
10
+Ralph Getz Perpignan Pediatre 0736397458
11
+Sarah Venhorst Arles Cardiologue 0718276125
12
+Dorothy Schrenk Dijon Psychiatre 0730529239
13
+Valerie Hill Courbevoie Gynecologue 0740938552
14
+Bethany Hemmingsen Belfort Pharmacien 0661965668
15
+Alex Sircy Carcassonne Dentiste 0767042063
16
+Dawn Orduna Limoges Pharmacien 0729276847
17
+John Roberts Valence Ophtalmologie 0606017296
18
+Kirk Mentzer Beziers Stomatologue 0754938171
19
+Rod Brandes Beauvais Ophtalmologie 0677493599
20
+Ann Collins Drancy Rhumatologue 0728051106
21
+Lyle Lynch Bordeaux Pneumologue 0611081673
22
+Daniel Gaytan Nimes Dentiste 0734320107
23
+Maria Clayton Cayenne Stomatologue 0707951067
24
+Michelle Szaflarski Bourges Rhumatologue 0671359079
25
+Connie Myles Rouen Psychiatre 0670774856
26
+Michelle Koller Angers Orthodontiste 0789861804
27
+Burton Gould Meaux Kinesitherapeute 0759713789
28
+William Downs Metz Urologue 0624420780
29
+Warren Thacker Cannes Pharmacien 0787114057
30
+Gabrielle Atwood Vincennes Kinesitherapeute 0717448326
31
+Nancy Schlemmer Cergy Stomatologue 0680012397
32
+Joshua Sheahan Belfort ORL 0751676741
33
+Janet Matusz Limoges Infirmier 0679596606
34
+June Phillips Frejus Cardiologue 0794575429
35
+Bonnie Henry Bourges Pharmacien 0733255479
36
+Brad Tinajero Niort ORL 0787004064
37
+Diane Brody Paris Stomatologue 0619689557
38
+Andrew Brizuela Perpignan Veterinaire 0725147359
39
+Tiffany Johnson Montpellier Cardiologue 0662233729
40
+Jean Ball Beauvais Psychologue 0619930405
41
+Edwin Womack Pessac Cardiologue 0610446516
42
+Walter Lee Mulhouse Urologue 0736737546
43
+Lionel Garrison Sarcelles Urologue 0626162381
44
+Ted Ross Limoges Dermatologue 0736812823
45
+Joseph Burgos Merignac Dermatologue 0686454461
46
+Helen Rudd Suresnes Rhumatologue 0720159880
47
+John Edwards Colombes Stomatologue 0786816630
48
+Patricia Mckenzie Bayonne Radiologue 0799285175
49
+Barry Washington Carcassonne Gynecologue 0629044930
50
+Brent Rumph Dunkerque Kinesitherapeute 0601686369
51
+Howard Hopper Calais Gynecologue 0736698485
52
+Willie Morber Pessac Pharmacien 0684229819
53
+Debra Ferro Argenteuil Dermatologue 0715229166
54
+Jewell Browne Clamart Infirmier 0613448062
55
+Marjorie Phillips Beziers Dentiste 0626771559
56
+Bobbie Dickson Roubaix Veterinaire 0752944999
57
+Dorothy Taylor Drancy Pneumologue 0727657312
58
+Shelley Toure Albi Ophtalmologie 0728248225
59
+Jacqueline Lowe Lorient Psychologue 0766130683
60
+Thelma Joyce Sartrouville Psychologue 0782053265
61
+Taneka Bonnell Nancy Gynecologue 0708715730
62
+Johnny Verduzco Martigues Dermatologue 0640313570
63
+Lydia Stahnke Perpignan Gynecologue 0654914801
64
+Noel Seng Colmar Pharmacien 0640985650
65
+Patricia Mancia Nantes Pharmacien 0661452251
66
+Andrew Edison Cannes Infirmier 0682646757
67
+George Chan Clichy Pediatre 0704365146
68
+Laura Krajewski Tours Pneumologue 0728727260
69
+Matthew Ringwood Cergy Oncologue 0769681461
70
+Kenneth Cox Sevran Pneumologue 0651190403
71
+Odell Anderson Dijon Dentiste 0644008941
72
+Cynthia Stelling Antony Pneumologue 0709334530
73
+Fred Collins Lyon Psychiatre 0768046535
74
+Robert Rose Paris Dermatologue 0696752326
75
+Ronald Carpenter Tourcoing ORL 0798115523
76
+Carolyn Jordan Montrouge Ophtalmologie 0670251464
77
+Scott Harris Montpellier Orthodontiste 0671519724
78
+John Turner Brest Urologue 0666825542
79
+Arturo Strobel Lorient Veterinaire 0718350189
80
+Mary Byrd Calais ORL 0770391790
81
+Maria Castillo Villejuif Psychiatre 0640320392
82
+Helen Smith Venissieux Cardiologue 0710300526
83
+Elizabeth Runyon Lyon Cardiologue 0754831274
84
+Irma Lebeau Chambery Veterinaire 0622965436
85
+Raul Petrick Orleans Gynecologue 0782714832
86
+Genevieve White Sartrouville Kinesitherapeute 0701551618
87
+Charlotte Allred Lyon Psychologue 0779128443
88
+Ashley Golish Clichy Dermatologue 0733829538
89
+Christopher Marshall Perpignan Pneumologue 0608430736
90
+Patricia Martinez Creteil Urologue 0708675019
91
+Shawn Depue Quimper Urologue 0771007917
92
+James Whitaker Antibes Rhumatologue 0708105493
93
+Venus Heath Merignac Ophtalmologie 0764982294
94
+Henry Taylor Quimper Pediatre 0627414030
95
+Gerald Ward Antony Infirmier 0760432900
96
+Pearlie Wallace Lorient Oncologue 0678446542
97
+Darrell Dingman Aubervilliers Pneumologue 0742554197
98
+John Wingard Vincennes Rhumatologue 0610835804
99
+Regina Mitchell Cergy Kinesitherapeute 0799055623
100
+Amanda Johnson Paris Pharmacien 0783971691

+ 50000
- 0
semestre4/TP3_paquetages_generiques/2015-02-16_11-35-27_Annuaire_50000.txt
File diff suppressed because it is too large
View File


+ 11
- 0
semestre4/TP3_paquetages_generiques/afficher_test.adb View File

@@ -0,0 +1,11 @@
1
+with Ada.Text_Io;
2
+
3
+procedure Afficher_Test(Objet_du_Test, Attendu, Obtenu : in  String) is
4
+begin
5
+   Ada.Text_Io.New_Line;
6
+   Ada.Text_Io.Put_Line("-----------------------------------------------------------");
7
+   Ada.Text_Io.Put_Line(Objet_du_Test);
8
+   Ada.Text_Io.Put_Line("Resultat attendu : " & Attendu);
9
+   Ada.Text_Io.Put_Line("Resultat obtenu  : " & Obtenu);
10
+   Ada.Text_Io.New_Line;
11
+end Afficher_Test;

+ 72
- 0
semestre4/TP3_paquetages_generiques/contacts.adb View File

@@ -0,0 +1,72 @@
1
+package body Contacts is
2
+
3
+   function Initialiser_Contact(Nom, Prenom, Ville, Specialite, Telephone : in String) return Un_Contact is
4
+   begin
5
+      return (new String'(Nom), new String'(Prenom), new string'(Ville), new string'(Specialite), new string'(Telephone));
6
+   end Initialiser_Contact;
7
+
8
+   function Nom(C : in Un_Contact) return String is
9
+   begin
10
+      return C.Nom.all;
11
+   end Nom;
12
+
13
+   function Prenom(C : in Un_Contact) return String is
14
+   begin
15
+      return C.Prenom.all;
16
+   end Prenom;
17
+
18
+   function Ville(C : in Un_Contact) return String is
19
+   begin
20
+      return C.Ville.all;
21
+   end Ville;
22
+
23
+   function Specialite(C : in Un_Contact) return String is
24
+   begin
25
+      return C.Specialite.all;
26
+   end Specialite;
27
+
28
+   function Telephone(C : in Un_Contact) return String is
29
+   begin
30
+      return C.Telephone.all;
31
+   end Telephone;
32
+
33
+   function Contact_To_String(C : in Un_Contact) return String is
34
+   begin
35
+      return C.Nom.all & " " & C.Prenom.all & " " & C.Ville.all & " " & C.Specialite.all & " " & C.Telephone.all;
36
+   end Contact_To_String;
37
+
38
+   function "="(C1, C2 : in Un_Contact) return Boolean is
39
+   begin
40
+      return C1.Nom.all = C2.Nom.all and C1.Prenom.all = C2.Prenom.all and C1.Ville.all = C2.Ville.all and C1.Specialite.all = C2.Specialite.all and C1.Telephone.all = C2.Telephone.all;
41
+   end "=";
42
+
43
+   function "<"(C1, C2 : in Un_Contact) return Boolean is
44
+   begin
45
+      return C1.Nom.all < C2.Nom.all or else (C1.Nom.all = C2.Nom.all and C1.Prenom.all < C2.Prenom.all);
46
+   end "<";
47
+
48
+   procedure Liberer_Contact(C : in out Un_Contact) is
49
+   begin
50
+      Liberer_String(C.Nom);
51
+      Liberer_String(C.Prenom);
52
+      Liberer_String(C.Ville);
53
+      Liberer_String(C.Specialite);
54
+      Liberer_String(C.Telephone);
55
+   end Liberer_Contact;
56
+   
57
+   function Slct_Spec(C : in Un_Contact) return Boolean is
58
+   begin
59
+      return C.Specialite.all = Choix;
60
+   end Slct_Spec;
61
+
62
+   function Slct_Nom(C : in Un_Contact) return Boolean is
63
+   begin
64
+      return C.Nom.all = Choix;
65
+   end Slct_Nom;
66
+
67
+   function Slct_Ville(C : in Un_Contact) return Boolean is
68
+   begin
69
+      return C.Ville.all = Choix;
70
+   end Slct_Ville;
71
+
72
+end Contacts;

+ 51
- 0
semestre4/TP3_paquetages_generiques/contacts.ads View File

@@ -0,0 +1,51 @@
1
+with Pointeurs_De_Strings;
2
+use  Pointeurs_De_Strings;
3
+
4
+package Contacts is
5
+
6
+   type Un_Contact is private;
7
+
8
+   --constructeur
9
+   function Initialiser_Contact(Nom, Prenom, Ville, Specialite, Telephone : in String) return Un_Contact;
10
+
11
+   --accesseurs
12
+   function Nom(C : in Un_Contact) return String;
13
+   function Prenom(C : in Un_Contact) return String;
14
+   function Ville(C : in Un_Contact) return String;
15
+   function Specialite(C : in Un_Contact) return String;
16
+   function Telephone(C : in Un_Contact) return String;
17
+
18
+   --conversion en chaine
19
+   function Contact_To_String(C : in Un_Contact) return String;
20
+
21
+   -- egalite
22
+   function "="(C1, C2 : in Un_Contact) return Boolean;
23
+
24
+   --relation d'ordre
25
+   function "<"(C1, C2 : in Un_Contact) return Boolean;
26
+
27
+   --recuperation memoire
28
+   procedure Liberer_Contact(C : in out Un_Contact);
29
+   
30
+   -- Fonction qui saura "regarder" au bon endroit selon ce qu'on demande
31
+   generic
32
+      Choix : String;
33
+   function Slct_Spec(C : in Un_Contact) return Boolean;
34
+   generic
35
+      Choix : String;
36
+   function Slct_Nom(C: in Un_Contact) return Boolean;
37
+   generic
38
+      Choix : String;
39
+   function Slct_Ville(C: in Un_Contact) return Boolean;
40
+
41
+private
42
+
43
+   type Un_Contact is record
44
+      Nom        : P_String;
45
+      Prenom     : P_String;
46
+      Ville      : P_String;
47
+      Specialite : P_String;
48
+      Telephone  : P_String;
49
+   end record;
50
+
51
+end Contacts;

+ 17
- 0
semestre4/TP3_paquetages_generiques/lire_mot.txt View File

@@ -0,0 +1,17 @@
1
+   procedure Lire_Mot(S : String; Deb, Fin : out Integer) is
2
+      -- cherche le debut et la fin du premier token
3
+      -- si aucun token n'est trouve on aura en sortie : Deb > Fin
4
+   begin
5
+      Deb := S'First;
6
+      Fin := Deb-1;
7
+      while Deb <= S'last and then S(Deb) = ' ' loop
8
+         Deb := Deb+1;    --recherche du debut du 1er mot
9
+      end loop;
10
+      if Deb <= S'Last then
11
+         Fin := Deb;
12
+         while Fin <= S'Last and then S(Fin) /= ' ' loop
13
+            Fin := Fin +1;   --recherche de la fin du 1er mot
14
+         end loop;
15
+         Fin  := Fin-1;
16
+      end if;
17
+   end Lire_Mot;

+ 4
- 0
semestre4/TP3_paquetages_generiques/listes_ordonnees_contacts.ads View File

@@ -0,0 +1,4 @@
1
+with Ada.Text_Io, listes_ordonnees_g, Contacts, Ada.Unchecked_Deallocation;
2
+use Contacts;
3
+
4
+package Listes_Ordonnees_Contacts is new Listes_Ordonnees_G(Un_Contact,"<", Contact_To_string, Liberer_contact);

+ 180
- 0
semestre4/TP3_paquetages_generiques/listes_ordonnees_g.adb View File

@@ -0,0 +1,180 @@
1
+with Ada.Unchecked_Deallocation;
2
+
3
+package body Listes_Ordonnees_g is
4
+
5
+   -------------------------------------------------------------------------
6
+   function Est_Vide(L : in Une_Liste_Ordonnee) return Boolean is
7
+   begin
8
+      return L.Debut = null;
9
+   end Est_Vide;
10
+   -------------------------------------------------------------------------
11
+
12
+   -------------------------------------------------------------------------
13
+   function Cardinal(L : in Une_Liste_Ordonnee) return Integer is
14
+   begin
15
+      return L.Taille;
16
+   end Cardinal;
17
+   -------------------------------------------------------------------------
18
+
19
+   -----------------------------------------------------------------------------
20
+   -- Appartient classique sur une liste simplement chainee (type Lien) ordonnee
21
+
22
+   function Appartient_Lien(E : Element; LL : in Lien) return Boolean is
23
+      Resultat : boolean;
24
+   begin
25
+      if LL = null or else E < LL.all.info then
26
+         Resultat := False;         -- element non trouve
27
+      elsif LL.all.Info = E then
28
+         Resultat := True;          -- element trouve en 1ere place
29
+      else
30
+         Resultat := Appartient_Lien(E, LL.all.Suiv);  -- on cherche plus loin
31
+      end if;
32
+      return Resultat;
33
+   end Appartient_Lien;
34
+
35
+   -- Appartient sur le type Une_Liste_Ordonnee_Entiers
36
+   -- On reutilise la fonction classique Appartient_Lien sur L.debut
37
+   function Appartient(E : in Element; L : in Une_Liste_Ordonnee) return Boolean is
38
+   begin
39
+      return Appartient_Lien(E, L.Debut);
40
+   end Appartient;
41
+   -------------------------------------------------------------------------
42
+
43
+   -------------------------------------------------------------------------
44
+   -- Conversion en chaine de caracteres
45
+   --
46
+   -- sur le type Lien
47
+
48
+   function Lien_To_String(LL : in Lien) return String is
49
+   begin
50
+      if LL = null then return "";
51
+                   else return Image(LL.all.info) & Lien_To_String(LL.all.suiv); 
52
+      end if;
53
+   end Lien_To_String;
54
+
55
+   -- sur le type Une_Liste_Ordonnee_Entiers
56
+   function Liste_To_String(L: in Une_Liste_Ordonnee) return String is
57
+   begin
58
+      return Integer'Image(L.Taille) & " elements : (" & Lien_To_String(L.Debut) & " )";
59
+   end Liste_To_String;
60
+   -------------------------------------------------------------------------
61
+
62
+   -------------------------------------------------------------------------
63
+   -- Insertion ORDONNEE et SANS DOUBLON
64
+   
65
+   procedure Inserer_Lien(E: in Element; L: in out Lien) is
66
+   begin
67
+      if L = null then
68
+	 L := new Cellule'(E, null);
69
+      elsif L.Info = E then raise Element_Deja_Present;
70
+      elsif E < L.info then
71
+	 L := new Cellule'(E, L);
72
+      else
73
+	 Inserer_Lien(E, L.Suiv);
74
+      end if;
75
+
76
+   -- On desire une version RECURSIVE
77
+   -- La procedure doit LEVER L'EXCEPTION Element_Deja_Present en
78
+   -- cas de tentative d'insertion d'un doublon
79
+   end Inserer_Lien;
80
+
81
+
82
+
83
+   -------------------------------------------------------------------------
84
+   procedure Inserer(E: in Element; L: in out Une_Liste_Ordonnee) is
85
+   begin
86
+      Inserer_Lien(E, L.Debut);
87
+      L.Taille := L.Taille + 1;
88
+   end Inserer;
89
+   -------------------------------------------------------------------------
90
+
91
+
92
+   -- Instanciation de Ada.Unchecked_Deallocation pour desallouer
93
+   -- la memoire en cas de suppression des elements d'une liste
94
+   -------------------------------------------------------------------------
95
+   procedure Free is new Ada.Unchecked_Deallocation(Cellule, Lien);
96
+   -------------------------------------------------------------------------
97
+   procedure Supprimer_Lien(E : in Element; L: in out Lien) is
98
+      Recup : Lien;
99
+   begin
100
+      if L = null or else E < L.All.Info then
101
+         raise Element_Non_Present;
102
+      elsif E = L.All.Info then
103
+         Recup := L;           -- on repere la cellule a recycler
104
+         L     := L.All.Suiv;  -- on modifie le debut de la liste
105
+	 Free_Element(Recup.all.Info);
106
+         Free(Recup);          -- on recupere la memoire
107
+      else
108
+         Supprimer_Lien(E, L.all.suiv);
109
+      end if;
110
+   end Supprimer_Lien;
111
+   -------------------------------------------------------------------------
112
+   procedure Supprimer(E: in Element; L: in out Une_Liste_Ordonnee) is
113
+   begin
114
+      Supprimer_Lien(E, L.debut);
115
+      L.Taille := L.Taille - 1;
116
+   end Supprimer;
117
+   -------------------------------------------------------------------------
118
+   
119
+   -------------------------------------------------------------------------
120
+   -- Fonctions facultatives
121
+   function Egal_Lien(L1, L2 : in Lien) return Boolean is
122
+   begin
123
+      if L1 = null and L2 = null then
124
+	 return True;
125
+      elsif (L1 = null or L2 = null) or (L1.Info /= L2.Info) then
126
+	 return False;
127
+      elsif L1.Info = L2.Info then
128
+	 return Egal_Lien(L1.all.Suiv, L2.all.Suiv);
129
+      else
130
+	 return FALSE; -- Ligne de code jamais atteinte, mais supprime des messages d'erreurs à la compilation.
131
+      end if;
132
+   end Egal_Lien;
133
+   
134
+   function "="(L1, L2 : in Une_Liste_Ordonnee) return Boolean is
135
+   begin
136
+      return Egal_Lien(L1.Debut, L2.Debut);
137
+   end "=";
138
+   
139
+   procedure Copie_Lien_obsolete(L1: in Lien; L2 : out Lien) is
140
+      P1 : Lien := L1;
141
+      P2 : Lien := null;
142
+   begin
143
+      L2 := P2;
144
+      if L1 /= null then
145
+	 P2 := new Cellule'(P1.all.Info, null);
146
+	 L2 := P2;
147
+	 P1 := P1.all.Suiv;
148
+	 while P1 /= null loop
149
+	    P2.all.Suiv := new Cellule'(P1.all.Info, null);
150
+	    P2 := P2.all.Suiv;
151
+	    P1 := P1.all.Suiv;
152
+	 end loop;
153
+      end if;
154
+   end Copie_Lien_Obsolete;
155
+   
156
+   function Copie_Lien(L1: in Lien) return Lien is
157
+   begin
158
+      if L1 = null then return null;
159
+      else return new Cellule'(L1.all.Info, Copie_Lien(L1.all.Suiv)); 
160
+      end if; 
161
+   end Copie_Lien;
162
+   
163
+   procedure Copie(L1 : in Une_Liste_Ordonnee; L2 : out Une_Liste_Ordonnee) is
164
+   begin
165
+      L2.Debut := Copie_lien(L1.Debut);
166
+      L2.Taille := L1.Taille;
167
+   end Copie;
168
+   
169
+   procedure Filtrage(L: in out Une_Liste_Ordonnee) is
170
+      P : Lien := L.Debut;
171
+   begin
172
+      while P /= null loop
173
+	 if not Critere(P.Info) then 
174
+	    Supprimer(P.Info, L);
175
+	 end if;
176
+	 P := P.all.Suiv;
177
+      end loop;
178
+   end Filtrage;
179
+   
180
+end Listes_Ordonnees_g;

+ 51
- 0
semestre4/TP3_paquetages_generiques/listes_ordonnees_g.ads View File

@@ -0,0 +1,51 @@
1
+generic
2
+   type Element is private;
3
+   with function "<"(E1, E2: in Element) return Boolean;
4
+   with function Image(E1 : in Element) return String;
5
+   with procedure Free_Element(E : in out Element);
6
+   
7
+package Listes_Ordonnees_g is
8
+   
9
+   type Une_Liste_Ordonnee is limited private;
10
+
11
+   Element_Non_Present, Element_Deja_Present : exception;
12
+
13
+   function Est_Vide(L : in Une_Liste_Ordonnee) return Boolean;
14
+
15
+   function Cardinal(L : in Une_Liste_Ordonnee) return Integer;
16
+
17
+   function Appartient(E : in Element; L : in Une_Liste_Ordonnee) return Boolean;
18
+
19
+   procedure Inserer(E: in Element; L: in out Une_Liste_Ordonnee);
20
+
21
+   procedure Supprimer(E: in Element; L: in out Une_Liste_Ordonnee);
22
+
23
+   function Liste_To_String(L: in Une_Liste_Ordonnee) return String;
24
+
25
+   --ajouts de ss-programmes d'egalite et de copie
26
+   function "="(L1, L2 : in Une_Liste_Ordonnee) return Boolean;
27
+
28
+   procedure Copie(L1 : in Une_Liste_Ordonnee; L2 : out Une_Liste_Ordonnee);
29
+   
30
+   generic
31
+      with function Critere(E: in Element) return Boolean;
32
+   procedure Filtrage(L: in out Une_Liste_Ordonnee);
33
+
34
+
35
+private
36
+   -- types classiques permettant de realiser des listes simplement chainees
37
+   type Cellule;
38
+   type Lien    is access Cellule;
39
+   type Cellule is record
40
+        Info : Element;
41
+        Suiv : Lien;
42
+   end record;
43
+
44
+   -- type liste ameliore : record contenant la liste et sa taille
45
+   -- (evite de parcourir la liste pour calculer la taille)
46
+
47
+   type Une_Liste_Ordonnee is record
48
+      Debut  : Lien    := null;
49
+      Taille : Natural := 0;
50
+   end record;
51
+end Listes_Ordonnees_g;

+ 9
- 0
semestre4/TP3_paquetages_generiques/pointeurs_de_strings.ads View File

@@ -0,0 +1,9 @@
1
+with Ada.Unchecked_Deallocation;
2
+
3
+package Pointeurs_De_Strings is
4
+	
5
+	type P_String is access String;
6
+
7
+	procedure Liberer_String is new Ada.Unchecked_Deallocation(String , P_String);
8
+
9
+end Pointeurs_De_Strings;

BIN
semestre4/TP3_paquetages_generiques/tester_liste_contacts View File


+ 274
- 0
semestre4/TP3_paquetages_generiques/tester_liste_contacts.adb View File

@@ -0,0 +1,274 @@
1
+with Ada.Text_Io; use Ada.Text_Io;
2
+with Ada.IO_Exceptions;
3
+with Contacts; use Contacts;
4
+with Afficher_Test;
5
+with Listes_Ordonnees_Contacts; use Listes_Ordonnees_Contacts;
6
+
7
+procedure Tester_Liste_Contacts is  
8
+   
9
+   function Critere(C: in Un_Contact) return Boolean is
10
+   begin
11
+      return Ville(C) = "Beauvais";
12
+   end Critere;
13
+   
14
+   procedure Filtre is new Filtrage(Critere);
15
+   
16
+   Fichier : File_Type;
17
+   Chaine, Ligne, crit : String(1..80);
18
+   Len, last : Integer := 0;
19
+   L_ann : Une_Liste_Ordonnee;
20
+   C : Un_Contact;
21
+   
22
+   Rep : Character;
23
+   Prenom, Nom, Ville, Specia, Telephone, Fin, I : Integer := 0;
24
+begin
25
+   
26
+   -----------------------------------------------------------
27
+   -- Utilisation d'annuaires
28
+   -----------------------------------------------------------
29
+   
30
+   -- Entourloupe pour avoir un nom de fichier contraint, saisi par l'utilisateur et de bonne taille
31
+   Put_Line("Lecture d'un fichier de contact, veillez saisir le nom du fichier : ");
32
+   Get_Line(Chaine, Len);
33
+   declare
34
+      Nom_Fichier : String(Chaine'First..Len) := Chaine(Chaine'First..Len);
35
+   begin
36
+      open(Fichier, in_File, Nom_Fichier);
37
+      while not End_Of_File(Fichier) loop
38
+	 Get_Line (Fichier,  Ligne ,  Len ) ; 
39
+	 Put_Line ( "Ajouté à l'annuaire: " & Ligne(1..Len));
40
+	 
41
+	 Prenom := 1;
42
+	 Nom := 0;
43
+	 Ville := 0;
44
+	 Specia := 0;
45
+	 Telephone := 0;
46
+	 Fin := 0;
47
+	 I := 1;
48
+	 
49
+	 while Telephone = 0 loop
50
+	    if Ligne(I) = ' ' then
51
+	       if Nom = 0 then Nom := I;
52
+	       elsif Ville = 0 then Ville := I;
53
+	       elsif Specia = 0 then Specia := I;
54
+	       elsif Telephone = 0 then Telephone := I; Fin := Telephone + 10; 
55
+	       end if;
56
+	    end if;
57
+	    I := I + 1;
58
+	 end loop;
59
+	 C := Initialiser_Contact(Ligne(Prenom..Nom-1), Ligne(Nom+1..Ville-1), Ligne(Ville+1..Specia-1), Ligne(Specia+1..Telephone-1), Ligne(Telephone+1..Fin-1) & " ");
60
+	 Inserer(C, L_Ann);
61
+      end loop;
62
+      Close(Fichier);
63
+      
64
+      
65
+      -----------------------------------------------------------
66
+      -- Test sur annuaire
67
+      -----------------------------------------------------------
68
+      New_Line;
69
+      Put_Line("Test sur l'annuaire fournis"); 
70
+      
71
+      Afficher_Test("Est_Vide() ?", "Inconnu", Boolean'Image(Est_Vide(L_ann)));
72
+      Afficher_Test("Cardinal() ?", "Inconnu", Integer'Image(Cardinal(L_ann)));
73
+      
74
+      Put_Line("Vous avez saisi l'annuaire suivant : ");
75
+      Put_Line(Liste_To_String(L_ann)); New_Line;
76
+      
77
+      Put_Line("Test de filtrage : ");
78
+      Filtre(L_Ann);
79
+      Put_Line("...filtrée :");
80
+      Put_Line(Liste_To_String(L_ann)); New_Line;
81
+      
82
+      ----------------------------------------------------------
83
+      
84
+      -- Choix Utilisateur à partir des fonctions génériques
85
+      Put_line("Choix: Nom(0), Ville(1), Specialite(2) ");
86
+      Get(Rep); Skip_Line;
87
+
88
+      case Rep is
89
+	 when '0' => 
90
+	    Put_Line("Valeur du nom recherche : ");
91
+	    Get_Line(Crit, Last);
92
+	    declare
93
+	       function Selection_Nom is new Slct_Nom(Crit(1..Last));
94
+	       procedure FiltrerNom   is new Filtrage(Selection_Nom);
95
+	    begin
96
+	       FiltrerNom(L_ann);
97
+	       Put_Line("Liste de contacts filtres : ");
98
+	       Put(Liste_To_String(L_ann));
99
+	    end;
100
+
101
+	 when '1' => 
102
+	    Put_Line("Valeur de la ville recherchee : ");
103
+	    Get_Line(Crit, Last);
104
+	    declare
105
+	       function Selection_Ville is new Slct_Ville(Crit(1..Last));
106
+	       procedure FiltrerVille is   new Filtrage(Selection_Ville);
107
+	    begin
108
+	       FiltrerVille(L_ann);
109
+	       Put_Line("Liste de contacts filtres : ");
110
+	       Put(Liste_To_String(L_ann));
111
+	    end;
112
+
113
+	 when '2' => 
114
+	    Put_Line("Valeur de la specialite recherchee : ");
115
+	    Get_Line(Crit, Last);
116
+
117
+	    declare
118
+	       function Selection_Specialite is new Slct_Spec(Crit(1..Last));
119
+	       procedure FiltrerSpecialite is   new Filtrage(Selection_Specialite);
120
+	    begin
121
+	       FiltrerSpecialite(L_ann);
122
+	       Put_Line("Liste de contacts filtres : ");
123
+	       Put(Liste_To_String(L_ann));
124
+	    end;
125
+         when others => null;
126
+      end case;
127
+      
128
+      ----------------------------------------------------------
129
+      
130
+      New_Line;
131
+      Put_Line("---------------------------");
132
+      Put_Line("FIN DES TESTS AVEC ANNUAIRE");
133
+      Put_Line("---------------------------");
134
+      New_Line;
135
+      
136
+      -----------------------------------------------------------
137
+      -- Test de création
138
+      -----------------------------------------------------------
139
+      Put_Line("Test après création");
140
+      declare
141
+	 L : Une_Liste_Ordonnee;
142
+      begin
143
+	 Afficher_Test("Est_Vide() ?", "TRUE", Boolean'Image(Est_Vide(L)));
144
+	 Afficher_Test("Cardinal() ?", "0", Integer'Image(Cardinal(L)));
145
+	 
146
+	 Put_Line("Test d'affichage: ");
147
+	 Put_Line(Liste_To_String(L)); New_Line;
148
+      end;
149
+      -----------------------------------------------------------
150
+      
151
+      
152
+      -----------------------------------------------------------
153
+      -- Test d'ajout d'éléments
154
+      -----------------------------------------------------------
155
+      Put_Line("Test après ajout d'éléments");
156
+      declare
157
+	 L : Une_Liste_Ordonnee;
158
+	 C1 : Un_Contact := Initialiser_Contact("Charles", "Chang", "Beziers", "ORL", "0703888032");
159
+	 C2 : Un_Contact := Initialiser_Contact("Martha", "Bibbs", "Beauvais", "Psychiatre", "0616751216");
160
+	 C3 : Un_Contact := Initialiser_Contact("Jerry", "Joosten", "Albi", "Pharmacien", "0724258260");
161
+	 C4 : Un_Contact := Initialiser_Contact("Elijah", "Taylor", "Caen", "Orthodontiste", "0770222606");
162
+      begin
163
+	 Put_Line("Liste créée, on ajout des éléments");
164
+	 Inserer(C1,L);
165
+	 Inserer(C2,L);
166
+	 Inserer(C3,L);
167
+	 Inserer(C4,L);
168
+	 Put_Line("4 éléments ajoutés");
169
+	 
170
+	 Put_Line("Test d'affichage: ");
171
+	 Put_Line(Liste_To_String(L)); New_Line;
172
+	 
173
+	 Afficher_Test("Est_Vide() ?", "FALSE", Boolean'Image(Est_Vide(L)));
174
+	 Afficher_Test("Cardinal() ?", "4", Integer'Image(Cardinal(L)));
175
+	 Afficher_Test("Appartient(C2) ?", "TRUE", Boolean'Image(Appartient(C2,L)));
176
+      end;
177
+      -----------------------------------------------------------
178
+      
179
+      
180
+      -----------------------------------------------------------
181
+      -- Test de manipulation
182
+      -----------------------------------------------------------
183
+      Put_Line("Test de manipulation");
184
+      declare
185
+	 L : Une_Liste_Ordonnee;
186
+	 C1 : Un_Contact := Initialiser_Contact("Charles", "Chang", "Beziers", "ORL", "0703888032");
187
+	 C2 : Un_Contact := Initialiser_Contact("Martha", "Bibbs", "Beauvais", "Psychiatre", "0616751216");
188
+	 C3 : Un_Contact := Initialiser_Contact("Jerry", "Joosten", "Albi", "Pharmacien", "0724258260");
189
+	 C4 : Un_Contact := Initialiser_Contact("Elijah", "Taylor", "Caen", "Orthodontiste", "0770222606");
190
+      begin
191
+	 Put_Line("Liste créée, on ajout des éléments");
192
+	 Inserer(C1,L);
193
+	 Inserer(C2,L);
194
+	 Inserer(C3,L);
195
+	 Inserer(C4,L);
196
+	 Put_Line("Liste créée, 4 éléments ajoutés");
197
+	 Put_Line("Liste: ");
198
+	 Put_Line("On supprime C2:"); Supprimer(C2,L);
199
+	 Afficher_Test("Cardinal() ?", "3", Integer'Image(Cardinal(L)));
200
+	 Afficher_Test("Appartient(C2) ?", "FALSE", Boolean'Image(Appartient(C2,L)));
201
+      end;
202
+      -----------------------------------------------------------
203
+      
204
+      
205
+      -----------------------------------------------------------
206
+      -- Test d'exceptions
207
+      -----------------------------------------------------------
208
+      declare
209
+	 L : Une_Liste_Ordonnee;
210
+	 C1 : Un_Contact := Initialiser_Contact("Charles", "Chang", "Beziers", "ORL", "0703888032");
211
+	 C2 : Un_Contact := Initialiser_Contact("Martha", "Bibbs", "Beauvais", "Psychiatre", "0616751216");
212
+	 C3 : Un_Contact := Initialiser_Contact("Jerry", "Joosten", "Albi", "Pharmacien", "0724258260");
213
+	 C4 : Un_Contact := Initialiser_Contact("Elijah", "Taylor", "Caen", "Orthodontiste", "0770222606");
214
+      begin
215
+	 Put_Line("Liste créée, on ajout des éléments");
216
+	 Inserer(C1,L);
217
+	 Inserer(C2,L);
218
+	 Inserer(C3,L);
219
+	 Put_Line("On supprime un élément inexistant : ");
220
+	 Supprimer(C4, L);
221
+      exception
222
+	 when Element_Non_Present => Put_Line("L'exception Element_Non_Present est correctement levée !");
223
+      end;
224
+      declare
225
+	 L : Une_Liste_Ordonnee;
226
+	 C1 : Un_Contact := Initialiser_Contact("Charles", "Chang", "Beziers", "ORL", "0703888032");
227
+	 C2 : Un_Contact := Initialiser_Contact("Martha", "Bibbs", "Beauvais", "Psychiatre", "0616751216");
228
+	 C3 : Un_Contact := Initialiser_Contact("Jerry", "Joosten", "Albi", "Pharmacien", "0724258260");
229
+	 C4 : Un_Contact := Initialiser_Contact("Elijah", "Taylor", "Caen", "Orthodontiste", "0770222606");
230
+      begin
231
+	 Put_Line("Liste créée, on ajout des éléments");
232
+	 Inserer(C1,L);
233
+	 Inserer(C2,L);
234
+	 Put_Line("On ajoute un élément déjà présent : ");
235
+	 Inserer(C2, L);
236
+      exception
237
+	 when Element_Deja_Present => Put_Line("L'exception Element_Deja_Present est correctement levée !");
238
+      end;
239
+      -----------------------------------------------------------
240
+      
241
+      
242
+      -----------------------------------------------------------
243
+      -- Test des fonctions auxiliaires
244
+      -----------------------------------------------------------
245
+      declare
246
+	 L, L2 : Une_Liste_Ordonnee;
247
+	 C1 : Un_Contact := Initialiser_Contact("Charles", "Chang", "Beziers", "ORL", "0703888032");
248
+	 C2 : Un_Contact := Initialiser_Contact("Martha", "Bibbs", "Beauvais", "Psychiatre", "0616751216");
249
+	 C3 : Un_Contact := Initialiser_Contact("Jerry", "Joosten", "Albi", "Pharmacien", "0724258260");
250
+	 C4 : Un_Contact := Initialiser_Contact("Elijah", "Taylor", "Caen", "Orthodontiste", "0770222606");
251
+      begin
252
+	 New_Line;
253
+	 Put_Line("Test des fonctions auxilaires (=)");
254
+	 Put_Line("Liste créée, on ajout des éléments");
255
+	 Inserer(C1,L);
256
+	 Inserer(C2,L);
257
+	 Inserer(C3,L);
258
+	 Inserer(C4,L);
259
+	 Put_Line(Liste_To_String(L)); New_Line;
260
+	 Put_Line("On en créé une copie L2: ");
261
+	 Copie(L, L2);
262
+	 Put_Line(Liste_To_String(L2)); New_Line;
263
+	 
264
+	 Put_Line("On vérifie qu'elles sont égales:");
265
+	 Afficher_Test("=(L,L2) ?", "TRUE", Boolean'Image(L=L2));
266
+      end;
267
+      -----------------------------------------------------------
268
+      
269
+      New_Line;
270
+      Put_Line("Fin des tests.");
271
+   exception
272
+      when ADA.IO_EXCEPTIONS.NAME_ERROR => Put_Line("Fichier invalide.");
273
+   end;
274
+end Tester_Liste_Contacts;

BIN
semestre4/TP3_paquetages_generiques/tester_liste_ordonnee_entiers View File


+ 117
- 0
semestre4/TP3_paquetages_generiques/tester_liste_ordonnee_entiers.adb View File

@@ -0,0 +1,117 @@
1
+with Ada.Text_Io, listes_ordonnees_g, Afficher_Test, Ada.Unchecked_Deallocation;
2
+use  Ada.Text_Io;
3
+
4
+procedure Tester_Liste_Ordonnee_Entiers is
5
+   procedure Free_Null(I: in Integer) is
6
+   begin
7
+      null;
8
+   end Free_Null;
9
+   
10
+   package Listes_Entiers is new Listes_Ordonnees_G(Integer,"<", Integer'Image, Free_Null);
11
+   use Listes_Entiers;
12
+begin
13
+   -----------------------------------------------------------
14
+   -- Test de création
15
+   -----------------------------------------------------------
16
+   Put_Line("Test après création");
17
+   declare
18
+      L : Une_Liste_Ordonnee;
19
+   begin
20
+      Afficher_Test("Est_Vide() ?", "TRUE", Boolean'Image(Est_Vide(L)));
21
+      Afficher_Test("Cardinal() ?", "0", Integer'Image(Cardinal(L)));
22
+      
23
+      Put_Line("Test d'affichage: ");
24
+      Put_Line(Liste_To_String(L)); New_Line;
25
+   end;
26
+   -----------------------------------------------------------
27
+   
28
+   
29
+   -----------------------------------------------------------
30
+   -- Test d'ajout d'éléments
31
+   -----------------------------------------------------------
32
+   Put_Line("Test après ajout d'éléments");
33
+   declare
34
+       L : Une_Liste_Ordonnee;
35
+   begin
36
+      Put_Line("Liste créée, on ajout des éléments");
37
+      Inserer(1,L);
38
+      Inserer(-1,L);
39
+      Inserer(3,L);
40
+      Inserer(45,L);
41
+      Inserer(2,L);
42
+      Inserer(9,L);
43
+      Put_Line("6 éléments ajoutés : [1, -1, 3, 45, 2, 9].");
44
+      
45
+      Put_Line("Test d'affichage: ");
46
+      Put_Line(Liste_To_String(L)); New_Line;
47
+      
48
+      Afficher_Test("Est_Vide() ?", "FALSE", Boolean'Image(Est_Vide(L)));
49
+      Afficher_Test("Cardinal() ?", "6", Integer'Image(Cardinal(L)));
50
+      Afficher_Test("Appartient(2) ?", "TRUE", Boolean'Image(Appartient(2,L)));
51
+   end;
52
+   -----------------------------------------------------------
53
+   
54
+   
55
+   -----------------------------------------------------------
56
+   -- Test de manipulation
57
+   -----------------------------------------------------------
58
+   Put_Line("Test de manipulation");
59
+   declare
60
+      L : Une_Liste_Ordonnee;
61
+   begin
62
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);Inserer(45,L);Inserer(2,L);Inserer(9,L);
63
+      Put_Line("Liste créée, 6 éléments ajoutés : [1, -1, 3, 45, 2, 9].");
64
+      Put_Line("Liste: ");
65
+      Put_Line(Liste_To_String(L)); New_Line;
66
+      Put_Line("On supprime 2:"); Supprimer(2,L);
67
+      Afficher_Test("Cardinal() ?", "5", Integer'Image(Cardinal(L)));
68
+      Afficher_Test("Appartient(2) ?", "FALSE", Boolean'Image(Appartient(2,L)));
69
+   end;
70
+   -----------------------------------------------------------
71
+   
72
+   
73
+   -----------------------------------------------------------
74
+   -- Test d'exceptions
75
+   -----------------------------------------------------------
76
+   declare
77
+      L : Une_Liste_Ordonnee;
78
+   begin
79
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);
80
+      Put_Line("On supprime un élément inexistant : ");
81
+      Supprimer(28, L);
82
+   exception
83
+      when Element_Non_Present => Put_Line("L'exception Element_Non_Present est correctement levée !");
84
+   end;
85
+   declare
86
+      L : Une_Liste_Ordonnee;
87
+   begin
88
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);
89
+      Put_Line("On ajoute un élément déjà présent : ");
90
+      Inserer(1, L);
91
+   exception
92
+      when Element_Deja_Present => Put_Line("L'exception Element_Deja_Present est correctement levée !");
93
+   end;
94
+   -----------------------------------------------------------
95
+   
96
+   
97
+   -----------------------------------------------------------
98
+   -- Test des fonctions auxiliaires
99
+   -----------------------------------------------------------
100
+   declare
101
+       L, L2 : Une_Liste_Ordonnee;
102
+   begin
103
+      Put_Line("On créé une liste L: ");
104
+      Inserer(1,L); Inserer(-1,L);Inserer(3,L);
105
+      Put_Line(Liste_To_String(L)); New_Line;
106
+      Put_Line("On en créé une copie L2: ");
107
+      Copie(L, L2);
108
+      Put_Line(Liste_To_String(L2)); New_Line;
109
+      
110
+      Put_Line("On vérifie qu'elles sont égales:");
111
+      Afficher_Test("=(L,L2) ?", "TRUE", Boolean'Image(L=L2));
112
+   end;
113
+   -----------------------------------------------------------
114
+   
115
+   New_Line;
116
+   Put_Line("Fin des tests.");
117
+end Tester_Liste_Ordonnee_Entiers;

+ 11
- 0
semestre4/TP4_arbres_binaires_genericite/afficher_test.adb View File

@@ -0,0 +1,11 @@
1
+with Ada.Text_Io;
2
+
3
+procedure Afficher_Test(Txt_Appel, Txt_Attendu, Txt_Obtenu : in  String) is
4
+begin
5
+   Ada.Text_Io.New_Line;
6
+   Ada.Text_Io.Put_Line("-----------------------------------------------------------");
7
+   Ada.Text_Io.Put_Line(Txt_Appel);
8
+   Ada.Text_Io.Put_Line("Attendu : " & Txt_Attendu);
9
+   Ada.Text_Io.Put_Line("Obtenu  : " & Txt_Obtenu);
10
+   Ada.Text_Io.New_Line;
11
+end Afficher_Test;

+ 1
- 0
semestre4/TP4_arbres_binaires_genericite/afficher_test.ads View File

@@ -0,0 +1 @@
1
+procedure Afficher_Test(Txt_Appel, Txt_Attendu, Txt_Obtenu : in  string);

+ 226
- 0
semestre4/TP4_arbres_binaires_genericite/arbre_bin_recherche_cle_g.adb View File

@@ -0,0 +1,226 @@
1
+-- Date : Mars 2015
2
+-- Auteur : MJ. Huguet
3
+-- 
4
+-- Objet : corps paquetage arbre binaire de recherche generique
5
+--
6
+-- Fait 
7
+-- 
8
+-----------------------------------------------------------------------------
9
+with Unchecked_Deallocation;
10
+with Ada.Text_IO; use Ada.Text_IO;
11
+
12
+package body Arbre_Bin_Recherche_Cle_G is
13
+   
14
+   -----------------------------------------------------------------------------
15
+   procedure Free_Noeud IS NEW Unchecked_Deallocation(Noeud, LienArbre);
16
+   
17
+   procedure Liberer_Lien(LA : in out LienArbre) is
18
+   begin
19
+      if LA /= null then
20
+         Liberer_Lien(LA.all.gauche); -- desallocation partie gauche
21
+         Liberer_Lien(LA.all.droite); -- desallocation partie droite
22
+         Liberer_Element(LA.All.Info);   -- desallocation contenu du noeud racine
23
+         Free_Noeud(LA);              -- desallocation noeud racine
24
+      end if;
25
+   end Liberer_Lien;
26
+   
27
+   procedure Liberer(A : in out Arbre) is
28
+   begin
29
+      Liberer_Lien(A.Debut);
30
+      A.Debut := null;
31
+      A.Taille := 0;
32
+   end Liberer;
33
+   -----------------------------------------------------------------------------
34
+   
35
+   function ">"(K1, K2 : Key) return Boolean is begin
36
+      return K2 < K1; end ">";
37
+   
38
+   -----------------------------------------------------------------------------
39
+   function Est_Vide(A : in Arbre) return Boolean is
40
+   begin
41
+      return A.Debut=null;
42
+   end Est_Vide;
43
+   -----------------------------------------------------------------------------
44
+   -----------------------------------------------------------------------------
45
+   function Taille(A : in Arbre) return Natural is
46
+   begin
47
+      return A.Taille;
48
+   end Taille;
49
+   -----------------------------------------------------------------------------
50
+   -----------------------------------------------------------------------------
51
+   function Racine(A: in Arbre) return Element is
52
+   begin
53
+      if Est_Vide(A) then
54
+	 raise Arbre_Vide;
55
+      else
56
+	 return A.Debut.all.Info;
57
+      end if;
58
+   end Racine;
59
+   -----------------------------------------------------------------------------
60
+   
61
+   -----------------------------------------------------------------------------
62
+   function Appartient_Lien(E : in Element; LA : in LienArbre) return Boolean is
63
+      -- Fait
64
+   begin
65
+      if LA = null then
66
+	 return False;
67
+      elsif Cle_de(LA.Info) > Cle_de(E) then
68
+	 return Appartient_Lien(E, LA.Gauche);
69
+      elsif Cle_de(LA.Info) < Cle_De(E) then
70
+	 return Appartient_Lien(E, LA.Droite);
71
+      else 
72
+	 return TRUE;
73
+      end if;
74
+   end Appartient_Lien;
75
+   
76
+   function Appartient(E : in Element; A : in Arbre) return Boolean is
77
+   begin
78
+      return Appartient_Lien(E, A.Debut);
79
+   end Appartient;
80
+   -----------------------------------------------------------------------------
81
+   
82
+   -----------------------------------------------------------------------------
83
+   function Lien_To_String(LA : in LienArbre) return String is
84
+      -- Fait
85
+   begin
86
+      if LA /= null then
87
+	 return Lien_To_String(LA.Gauche) & Element_To_String(LA.Info) & Lien_To_String(LA.Droite);
88
+      else return "";
89
+      end if;
90
+   end Lien_To_String;
91
+
92
+   function Arbre_To_String(A : in Arbre) return String is
93
+   begin
94
+      return "(" & Integer'Image(A.Taille) & "|" & Lien_To_String(A.Debut) & ")";
95
+   end Arbre_To_String;
96
+   -----------------------------------------------------------------------------
97
+   
98
+   -----------------------------------------------------------------------------
99
+   -- Fait en version itérative comme demandé, moins efficace que la version récursive 
100
+   procedure Inserer_Lien(E : in Element; LA : in out LienArbre) is
101
+      -- Fait
102
+      P, Prec : LienArbre := LA;
103
+   begin
104
+      if LA = null then                       -- Si l'arbre est vide, on ajoute un premier noeud
105
+	 LA := new Noeud'(E, null, null);
106
+      else                                    -- Sinon on parcourt l'arbre en fonction de la valeur
107
+	 while P /= null loop                 -- de E jusqu'à une case où l'on peut l'ajouter
108
+	    if Cle_De(E) > Cle_De(P.Info) then
109
+	       Prec := P;                     -- On mémorise la valeur du précédant à P également
110
+	       P := P.all.Droite;
111
+	    elsif Cle_De(E) < Cle_De(P.Info) then
112
+	       Prec := P;
113
+	       P := P.all.Gauche;
114
+	    else
115
+	       raise Element_Deja_Present;
116
+	    end if;
117
+	 end loop;
118
+	 
119
+	 if Prec.Gauche = null and then Cle_De(Prec.Info) > Cle_De(E) then
120
+	    Prec.Gauche := new Noeud'(E, null, null);
121
+	 elsif Prec.Droite = null and then Cle_De(Prec.Info) < Cle_De(E) then
122
+	    Prec.Droite := new Noeud'(E, null, null);
123
+	 else
124
+	    raise Program_Error;
125
+	 end if;
126
+      end if;
127
+   end Inserer_Lien;
128
+   
129
+   procedure Inserer(E : Element; A : in out Arbre) is
130
+   begin
131
+      Inserer_Lien(E, A.Debut);
132
+      A.Taille := A.Taille + 1;
133
+   end Inserer;
134
+   -----------------------------------------------------------------------------
135
+   
136
+   -----------------------------------------------------------------------------   
137
+   procedure Supprimer_Maxg(LA : in out LienArbre; Maxg : out Element) is
138
+      -- Fait
139
+      Buffer : LienArbre;
140
+   begin
141
+      if LA.Droite = null then
142
+	 Maxg := LA.Info;
143
+	 
144
+	 Buffer := LA.Gauche;                    -- Ces "tas" d'instructions (plusieurs arrivent
145
+	 LA.info := LA.Gauche.info;              -- ensuite) sont dû au fait qu'implémenter une
146
+	 LA.Droite := LA.Gauche.Droite;          -- fonction de copie valables dans tous les cas
147
+	 LA.Gauche := LA.Gauche.Gauche;          -- serait ajouter une compléxité non nécéssaire
148
+	 
149
+	 Liberer_Element(Buffer.Info);
150
+	 Free_Noeud(Buffer);
151
+      else
152
+	 Supprimer_Maxg(LA.Droite, Maxg);
153
+      end if;
154
+   end Supprimer_Maxg;
155
+   
156
+   procedure Supprimer_Lien(E : in Element; LA : in out LienArbre ) is
157
+      -- Fait (cf. page 41 poly)
158
+      Maxg : Element;
159
+      Buffer : LienArbre;
160
+   begin
161
+      if LA = null then raise Element_Non_Present;
162
+      elsif Cle_De(E) > Cle_De(LA.Info) then                 -- On cherche le lien supprimer
163
+	 Supprimer_Lien(E, LA.all.Droite);                   -- en récursif
164
+      elsif Cle_De(E) < Cle_De(LA.Info) then
165
+	 Supprimer_Lien(E, LA.all.Gauche);
166
+      else -- i.e. E = LA.info
167
+	 if LA.Droite = null and LA.Gauche = null then
168
+	    Maxg := LA.Info;
169
+	    Liberer_Lien(LA);
170
+	    LA := null;
171
+	 elsif LA.Droite = null then                         -- Pour des raisons techniques, il est
172
+	    Buffer := LA.Gauche;                             -- préférable de "vampiriser" le noeud
173
+	    LA.info := LA.Gauche.info;                       -- fils
174
+	    LA.Droite := LA.Gauche.Droite;
175
+	    LA.Gauche := LA.Gauche.Gauche;
176
+	    
177
+	    Liberer_Element(Buffer.Info);
178
+	    Free_Noeud(Buffer);
179
+	 elsif LA.Gauche = null then                         -- Idem
180
+	    Buffer := LA.Droite;
181
+	    LA.Info := LA.Droite.Info;
182
+	    LA.Gauche := LA.Droite.Gauche;
183
+	    LA.Droite := LA.Droite.Droite;
184
+	    
185
+	    Liberer_Element(Buffer.Info);
186
+	    Free_Noeud(Buffer);
187
+	 else                                                -- Ou on le remplace par une valeur 
188
+	    Supprimer_Maxg(LA.Gauche, Maxg);
189
+	    LA.Info := Maxg;
190
+	 end if;
191
+      end if;
192
+   end Supprimer_Lien;
193
+   
194
+   
195
+   procedure Supprimer(E : in Element; A : in out Arbre) is
196
+   begin
197
+      Supprimer_Lien(E, A.Debut);
198
+      A.Taille := A.Taille - 1;
199
+   end Supprimer;
200
+   -----------------------------------------------------------------------------
201
+   
202
+   
203
+   -----------------------------------------------------------------------------
204
+   function Recherche_Lien(C: in Key; LA : in LienArbre) return Element is
205
+   begin
206
+      if LA = null then raise Element_Non_Present;
207
+      elsif Cle_De(LA.Info) > C then
208
+	 return Recherche_Lien(C, LA.Gauche);
209
+      elsif Cle_De(LA.Info) < C then
210
+	   return Recherche_Lien(C, LA.Droite);
211
+      else
212
+	 return LA.Info;
213
+      end if;
214
+   end Recherche_Lien;
215
+   
216
+   function Rechercher_Par_Cle(C: in Key; A : in Arbre) return Element is
217
+   begin
218
+      return Recherche_Lien(C, A.Debut);
219
+   end Rechercher_Par_Cle;
220
+   -----------------------------------------------------------------------------
221
+   
222
+
223
+end Arbre_Bin_Recherche_Cle_G;
224
+
225
+
226
+

+ 92
- 0
semestre4/TP4_arbres_binaires_genericite/arbre_bin_recherche_cle_g.ads View File

@@ -0,0 +1,92 @@
1
+-- Date : Mars 2015
2
+-- Auteur : MJ. Huguet
3
+-- 
4
+-- Objet : specification arbre binaire de recherche generique
5
+-- 
6
+-- Remarque : 
7
+--  	les elements disposent d'une cle permettant de les identifier
8
+-----------------------------------------------------------------------------
9
+generic
10
+   type Element is private;
11
+   type Key is private;
12
+   with function Cle_De(E : in Element) return Key;
13
+   with function "<"(C1, C2 : in Key) return Boolean;
14
+   with function "="(C1, C2 : in Key) return Boolean;
15
+   with procedure Liberer_Element(E : in out Element);
16
+   with function Element_To_String(E : in Element) return String;   
17
+package Arbre_Bin_Recherche_Cle_G is
18
+      Element_Deja_Present, Element_Non_Present, Arbre_Vide : exception;
19
+
20
+      type Arbre is limited private;  -- A la declaration un arbre est initialise (arbre vide)
21
+
22
+      procedure Liberer(A : in out Arbre);
23
+      function Est_Vide(A : in Arbre) return Boolean;
24
+      function Taille(A : in Arbre) return Natural;
25
+      function Racine(A: in Arbre) return Element; -- peut lever l'exception Arbre_Vide
26
+      
27
+      -- function Appartient(E : in Element; A : in Arbre) return Boolean;
28
+      function Appartient(E : in Element; A : in Arbre) return Boolean;
29
+      
30
+      -- Chaine correspondant a un parcours infixe (Gauche-Racine-Droite)
31
+      function Arbre_To_String(A : in Arbre) return string;
32
+
33
+      procedure Inserer(E: in Element; A: in out Arbre );    -- peut lever l'exception Element_Deja_Present
34
+      procedure Supprimer(E : in Element; A : in out Arbre); -- peut lever l'exception Element_Non_Present
35
+      
36
+
37
+      function Rechercher_Par_Cle(C: in Key; A : in Arbre) return Element;
38
+      
39
+      
40
+      
41
+      
42
+      --function Sous_Arbre_Gauche(A : in Arbre) return Arbre;
43
+      --function Sous_Arbre_Droit(A : in Arbre) return Arbre;
44
+	  
45
+      -- parcourir infixe
46
+      --generic
47
+      --   with procedure Traiter(E : in Element);
48
+      --procedure Parcourir_GRD(A : in Arbre);
49
+
50
+      --procedure Impression_Couchee(A : in Arbre; Decalage : in String:= "");
51
+      
52
+      
53
+      --      Tab_Recherche : ARRAY(1..2) OF Natural := (0, 0);
54
+      -- Tab_Resu(1) ==> nb test
55
+      -- Tab_Resu(2) ==> nb parcours
56
+      --      Tab_Recherche_Ordre : ARRAY(1..2) OF Natural := (0, 0);
57
+      -- Tab_Resu(1) ==> nb test
58
+      -- Tab_Resu(2) ==> nb parcours
59
+
60
+   
61
+     -- Fonction permettant de rechercher dans la liste les elements verifiant
62
+      -- certaines proprietes (exprimees dans Filtrer)
63
+      --generic
64
+      --   with function Filtrer(E1, E2 : in Element) return boolean;
65
+      --function Rechercher(E : in Element; A : in Arbre) return Arbre;
66
+
67
+      -- Fonction permettant de rechercher dans la liste les elements verifiant
68
+      -- certaines proprietes (exprimees dans Filtrer) et avec des conditions
69
+      -- d'arrêt de la recherche
70
+      --generic
71
+      --   with function Filtrer(E1, E2 : in Element) return Boolean;
72
+      --   with function Direction_Filtrer(E1, E2 : in Element) return Boolean;
73
+      --function Rechercher_Ordre(E : in Element; A : in Arbre) return Arbre;
74
+
75
+
76
+private
77
+      type Noeud;
78
+
79
+      type LienArbre is access Noeud;
80
+      type Noeud is record
81
+         Info : Element;
82
+         Gauche : LienArbre;
83
+         Droite : LienArbre;
84
+      end record;
85
+	  
86
+      type Arbre is record
87
+	 Debut : LienArbre := null;
88
+	 Taille : natural := 0;
89
+      end record;
90
+
91
+END Arbre_Bin_Recherche_Cle_g;
92
+

+ 102
- 0
semestre4/TP4_arbres_binaires_genericite/contact_cle.adb View File

@@ -0,0 +1,102 @@
1
+-- Date : Mars 2015
2
+-- Auteur : MJ. Huguet
3
+-- 
4
+-- Objet : corps du paquetage Contact (avec cle)
5
+-- 
6
+-----------------------------------------------------------------------------
7
+package body Contact_Cle is
8
+
9
+   function Creer_Contact(Nom, Prenom, Ville, Specialite, Telephone : in String) return Un_Contact is
10
+   begin
11
+      return (new String'(Nom), new String'(Prenom), new string'(Ville), new string'(Specialite), Telephone);
12
+   end Creer_Contact;
13
+
14
+   function Nom(C : in Un_Contact) return String is
15
+   begin
16
+      return C.Nom.all;
17
+   end Nom;
18
+
19
+   function Prenom(C : in Un_Contact) return String is
20
+   begin
21
+      return C.Prenom.all;
22
+   end Prenom;
23
+
24
+   function Ville(C : in Un_Contact) return String is
25
+   begin
26
+      return C.Ville.all;
27
+   end Ville;
28
+	
29
+   function Specialite(C : in Un_Contact) return String is
30
+   begin
31
+      return C.Specialite.all;
32
+   end Specialite;
33
+		
34
+   function Telephone(C : in Un_Contact) return Cle_Contact is
35
+   begin
36
+      return C.Telephone;
37
+   end Telephone;
38
+	
39
+   function Contact_To_String(C : in Un_Contact) return String is
40
+   begin
41
+      return C.Nom.all & " " & C.Prenom.all & " " & C.Ville.all & " " & C.Specialite.all & " " & C.Telephone & "; ";
42
+   end Contact_To_String;
43
+
44
+
45
+   function Cle(C : in Un_Contact) return Cle_Contact is
46
+   begin
47
+      return C.Telephone;
48
+   end Cle;
49
+   
50
+   function "="(S1, S2 : in Cle_Contact) return Boolean is
51
+      Res : Boolean := True;
52
+      indice : Integer := S1'First;
53
+   begin
54
+      while Indice <= S1'Last and Res=True loop
55
+	 if S1(Indice) /= S2(Indice) then
56
+	    Indice := Indice+1;
57
+	 else
58
+	    Res := False;
59
+	 end if;
60
+      end loop;      
61
+      return Res;
62
+   end "=";
63
+
64
+   function "<"(S1, S2 : in Cle_Contact) return Boolean is
65
+      Res : Boolean := True;
66
+      indice : Integer := S1'First;
67
+   begin
68
+      while Indice <= S1'Last and Res=True loop
69
+	 if S1(Indice) < S2(Indice) then
70
+	    Indice := Indice+1;
71
+	 else
72
+	    Res := False;
73
+	 end if;
74
+      end loop;      
75
+      return Res;
76
+   end "<";
77
+   
78
+   procedure Liberer_Contact(C : in out Un_Contact) is
79
+   begin
80
+      Liberer_String(C.Nom);
81
+      Liberer_String(C.Prenom);
82
+      Liberer_String(C.Ville);
83
+      Liberer_String(C.Specialite);
84
+      --Liberer_String(C.Telephone);
85
+   end Liberer_Contact;
86
+   
87
+   
88
+   -- Egalite champ a champ sur les elements
89
+   function Equal(C1, C2 : in Un_Contact) return Boolean is
90
+   begin
91
+      return C1.Nom.all = C2.Nom.all and C1.Prenom.all = C2.Prenom.all and C1.Ville.all = C2.Ville.all and C1.Specialite.all = C2.Specialite.all and C1.Telephone = C2.Telephone;
92
+   end Equal;
93
+   
94
+   -- Ordre alphabetique sur nom et prenom
95
+   function Inf_OrdreAlpha(C1, C2 : in Un_Contact) return Boolean is
96
+   begin
97
+      return C1.Nom.all < C2.Nom.all or else (C1.Nom.all = C2.Nom.all and C1.Prenom.all < C2.Prenom.all);
98
+   end Inf_OrdreAlpha;
99
+   
100
+   
101
+   
102
+end Contact_Cle;

+ 46
- 0
semestre4/TP4_arbres_binaires_genericite/contact_cle.ads View File

@@ -0,0 +1,46 @@
1
+-- Date : Mars 2015
2
+-- Auteur : MJ. Huguet
3
+-- 
4
+-- Objet : specification paquetage Contact (avec cle)
5
+-- 
6
+-----------------------------------------------------------------------------
7
+with Pointeurs_De_Strings;
8
+use Pointeurs_De_Strings;
9
+
10
+package Contact_Cle is
11
+
12
+   type Un_Contact is private; 
13
+   subtype Cle_Contact is String(1..10);
14
+   
15
+   function Creer_Contact(Nom, Prenom, Ville, Specialite, Telephone : in String) return Un_Contact;
16
+   function Nom(C : in Un_Contact) return String;
17
+   function Prenom(C : in Un_Contact) return String;
18
+   function Ville(C : in Un_Contact) return String;
19
+   function Specialite(C : in Un_Contact) return String;
20
+   function Telephone(C : in Un_Contact) return Cle_Contact;
21
+	
22
+   function Contact_To_String(C : in Un_Contact) return String;
23
+   procedure Liberer_Contact(C : in out Un_Contact);
24
+   
25
+      -- Cle : le champ Telephone sous forme d'entier
26
+   -- fonction de comparaison sur la cle
27
+   function Cle(C : in Un_Contact) return Cle_Contact;
28
+   function"="(S1, S2 : Cle_Contact) return Boolean;
29
+   function"<"(S1, S2 : Cle_Contact) return Boolean;
30
+   
31
+   function Equal(C1, C2 : in Un_Contact) return Boolean;
32
+   function Inf_OrdreAlpha(C1, C2 : in Un_Contact) return Boolean;
33
+   
34
+   
35
+   
36
+private
37
+
38
+   type Un_Contact is record
39
+      Nom : P_String;
40
+      Prenom : P_String;
41
+      Ville : P_String;
42
+      Specialite : P_String;
43
+      Telephone : Cle_Contact;
44
+   end record;
45
+
46
+end Contact_Cle;

BIN
semestre4/TP4_arbres_binaires_genericite/gerer_annuaire_inverse View File


+ 231
- 0
semestre4/TP4_arbres_binaires_genericite/gerer_annuaire_inverse.adb View File

@@ -0,0 +1,231 @@
1
+with Ada.Text_Io; use Ada.Text_Io;
2
+with Contact_Cle; use Contact_Cle;
3
+with Arbre_Bin_Recherche_Cle_G;
4
+with Liste_Ordonnee_Cle_G;
5
+with Ada.IO_Exceptions;
6
+with Ada.Calendar; use Ada.Calendar; 
7
+with Ada.Command_Line; use Ada.Command_Line;
8
+
9
+
10
+procedure Gerer_Annuaire_Inverse is
11
+   
12
+   -------------------------------------------------------------------------
13
+   -- Parametre du programme
14
+   --
15
+   -- Attention avec une valeur à TRUE le chargement de document volumineux 
16
+   -- est beaucoup plus long.
17
+   
18
+   ANALYSE_AVEC_LISTE : Boolean := TRUE; 
19
+   
20
+   -------------------------------------------------------------------------
21
+   
22
+   
23
+   
24
+   -- Instanciation des paquetages
25
+   package Arbre_Contacts is new Arbre_Bin_Recherche_Cle_G(Un_Contact, Cle_contact, Cle, "<", "=", Liberer_Contact, Contact_To_string);
26
+   use Arbre_Contacts;
27
+   
28
+   package Liste_Contacts is new Liste_Ordonnee_Cle_G(Un_Contact, Cle_contact, Cle, "<", "=", Liberer_Contact, Contact_To_string);
29
+   use Liste_Contacts;
30
+   
31
+   procedure Att_Liste is begin
32
+      New_Line;
33
+      Put_Line("Attention l'utilisation de listes est ACTIVEE et non nécessaire !"); 
34
+      Put_Line("L'option peut être désactivé à la compilation ou en passant le ");
35
+      Put_Line("parametre -a à l'execution.");
36
+      New_Line;
37
+      Put_Line("L'argument -p peut être spécifié pour lancer des tests de performance.");
38
+      New_Line;
39
+   end Att_Liste;
40
+   
41
+   Invalid_Argument : exception;
42
+   
43
+   -- Variables pour la lecture du fichier annuaire
44
+   Fichier : File_Type;
45
+   Chaine, Ligne : String(1..80);
46
+   Len, last : Integer := 0;
47
+   AB : Arbre;
48
+   C : Un_Contact;
49
+   Tel : String(1..10);
50
+   Auto : Boolean := False;
51
+   Prenom, Nom, Ville, Specia, Telephone, Fin, I, compteur : Integer := 0;
52
+   
53
+   -- Variables liées aux listes
54
+   L : Une_Liste_Ordonnee;
55
+   AnL : Boolean := ANALYSE_AVEC_LISTE;
56
+   Performance : Boolean := False;
57
+   
58
+   -- Varaibles temps
59
+   T1, T2 , TA , TB: Time;
60
+   
61
+begin
62
+   Put_Line("Programme d'annuaire inversé - Version ABR");
63
+   
64
+   -- Analyse des arguments (s'il y en a)
65
+   if Argument_Count = 1 and then Argument(1) = "-a"  then AnL := FALSE; end if;
66
+   if Argument_Count = 1 and then Argument(1) = "-p"  then Performance := TRUE; end if;
67
+   
68
+   if Argument_Count = 2 and then ((Argument(1) = "-a" and Argument(2) = "-p") or ((Argument(1) = "-p" and Argument(2) = "-a"))) then AnL := FALSE; Performance := TRUE; end if;
69
+   
70
+   if Performance and not AnL then raise Invalid_Argument; end if;
71
+   
72
+   
73
+   
74
+   if AnL then Att_Liste; end if;
75
+   
76
+   -- Entourloupe pour avoir un nom de fichier contraint, saisi par l'utilisateur et de bonne taille
77
+   Put_Line("Nom de l'annuaire: ");
78
+   Get_Line(Chaine, Len);
79
+   
80
+   -- (1) Option de test simple: si on laisse le champ vide, l'annuaire "T_10.txt" sera chargé 
81
+   if Len = 0 and not AnL then Len := 12; Auto := True; end if;
82
+   
83
+   -- On récupère le contenu du fichier choisi
84
+   declare
85
+      Nom_Fichier : String(Chaine'First..Len) := Chaine(Chaine'First..Len);
86
+      Cle_Cherche : Cle_Contact;
87
+   begin
88
+      -- (1)
89
+      if Auto then Nom_Fichier := "A_150000.txt"; end if;
90
+      
91
+      -- On ouvre le fichier dans "Fichier"
92
+      open(Fichier, in_File, "./jeux_de_donnees/" & Nom_Fichier);
93
+      Put_Line("Début du chargemnt du fichier...");
94
+      Compteur := 0;
95
+      
96
+      -- Tant qu'on n'a pas atteint la fin du fichier
97
+      while not End_Of_File(Fichier) loop
98
+	 Get_Line (Fichier,  Ligne ,  Len ) ; 
99
+	 
100
+	 -- Variables pour marquer les positions des différents éléments
101
+	 Prenom := 1;
102
+	 Nom := 0;
103
+	 Ville := 0;
104
+	 Specia := 0;
105
+	 Telephone := 0;
106
+	 Fin := 0;
107
+	 I := 1;
108
+	 
109
+	 -- On transforme une chaine de caractère en contact
110
+	 while Telephone = 0 loop
111
+	    if Ligne(I) = ' ' then
112
+	       if Nom = 0 then Nom := I;
113
+	       elsif Ville = 0 then Ville := I;
114
+	       elsif Specia = 0 then Specia := I;
115
+	       elsif Telephone = 0 then Telephone := I; Fin := Telephone + 11; 
116
+	       end if;
117
+	    end if;
118
+	    I := I + 1;
119
+	 end loop;
120
+	 C := Creer_Contact(Ligne(Prenom..Nom-1), Ligne(Nom+1..Ville-1), Ligne(Ville+1..Specia-1), Ligne(Specia+1..Telephone-1), Ligne(Telephone+1..Fin-1));
121
+	 
122
+	 -- On insère le contact créé dans un arbre et / ou une liste
123
+	 Inserer(C, AB);
124
+	 if AnL then Inserer(C, L); end if;  -- Ssi l'option est activée
125
+	 
126
+	 -- Compte du nombre de contacts chargés pour un meilleur suivi
127
+	 Compteur := Compteur + 1;
128
+	 if (Compteur mod 1000) = 0 then
129
+	    Put_Line(Integer'Image(Compteur) & " contacts chargés");
130
+	    if AnL and then Compteur mod 10000 = 0 then Att_Liste; end if;
131
+	 end if;
132
+	 
133
+      end loop;
134
+      Put_Line("Fin du chargement du ficier...");
135
+      Close(Fichier);
136
+      Put_Line("Annuaire en mémoire.");
137
+      New_Line;
138
+      
139
+      
140
+      -- La liste contient l'annuaire donné
141
+      --Put_Line("Liste avec les contacts : ");
142
+      --Put_Line(Liste_To_String(L));
143
+      --New_Line;
144
+      
145
+      if not Performance then
146
+	 loop 
147
+	    -- L'arbre AB contient l'annuaire saisi
148
+	    -- on fait donc la recherche dans cet arbre
149
+	    
150
+	    Put_Line("Veillez saisir un numéro à rechercher: ");
151
+	    Get_Line(Cle_Cherche, Len);
152
+	    
153
+	    -- Recherche dans l'arbre
154
+	    Put_Line("Recherche de " & Cle_Cherche & " dans l'arbre");
155
+	    T1 := Clock;
156
+	    C := Rechercher_Par_Cle(Cle_cherche, AB);
157
+	    T2 := Clock;
158
+	    Put_Line("Entrée trouvée : " & Contact_To_String(C));
159
+	    Put_Line("La recherche a durée : " & Duration'Image(T2 - T1));
160
+	    New_Line;
161
+	    
162
+	    -- Recherche dans la liste
163
+	    if AnL then
164
+	       Put_Line("Recherche dans la liste : ");
165
+	       T1 := Clock;
166
+	       C := Rechercher_Par_Cle(Cle_cherche, L);
167
+	       T2 := Clock;
168
+	       Put_Line("Entrée trouvée : " & Contact_To_String(C));
169
+	       Put_Line("La recherche a durée : " & Duration'Image(T2 - T1));
170
+	    end if;
171
+	    
172
+	    New_Line;
173
+	 end loop;
174
+      end if;            
175
+      
176
+      
177
+      -----------------------------------------------------------------------------------
178
+      
179
+      -- Tests de performance
180
+      New_Line;
181
+      Put_Line("Test de performance des différentes structures : ");
182
+      
183
+      if not AnL then raise Invalid_Argument; end if;
184
+      
185
+      Put_Line("On recherche tout les éléments présent dans chaque structure.");
186
+      open(Fichier, in_File, "./jeux_de_donnees/performance/" & Nom_Fichier & ".perf");
187
+      
188
+      Put_Line("Recherche dans l'arbre : ");
189
+      TA := Clock;
190
+      while not End_Of_File(Fichier) loop
191
+	 Tel := Get_Line(Fichier)(1..10);
192
+	 Put("Arbre : Recherche de " & Tel & "... ");
193
+	 C := Rechercher_Par_Cle(Tel, AB);
194
+	 Put_Line("Trouvé !");
195
+      end loop;
196
+      TB := Clock;
197
+      
198
+      Put_Line("La recherche de l'ensemble des éléments dans un arbre a durée : " & Duration'Image(TB - TA));
199
+      New_Line;
200
+      
201
+      Reset(Fichier);
202
+      
203
+      Put_Line("Recherche dans la liste : ");
204
+      T1 := Clock;
205
+      while not End_Of_File(Fichier) loop
206
+	 Tel := Get_Line(Fichier)(1..10);
207
+	 Put("Liste : Recherche de " & Tel & "... ");
208
+	 C := Rechercher_Par_Cle(Tel, L);
209
+	 Put_Line("Trouvé !");
210
+      end loop;
211
+      T2 := Clock;
212
+
213
+      Put_Line("La recherche de l'ensemble des éléments dans une liste a durée : " & Duration'Image(T2 - T1));
214
+      New_Line;
215
+      
216
+      Put_Line("Résultats :");
217
+      Put_Line("Arbre : " & Duration'Image(TB - TA));
218
+      Put_Line("Liste : " & Duration'Image(T2 - T1));
219
+      
220
+      New_Line;
221
+      Put_Line("...fini.");
222
+      
223
+      
224
+      -----------------------------------------------------------------------------------
225
+      
226
+   exception
227
+      when Invalid_Argument => Put_Line("L'argument -a a été spécifié, les tests de performnces ne peuvent pas avoir lieu."); raise PROGRAM_ERROR;
228
+      when Arbre_Contacts.Element_Non_Present => Put_Line("Equivalence numéro introuvable.");
229
+      when ADA.IO_EXCEPTIONS.NAME_ERROR => Put_Line("Fichier invalide.");
230
+   end;
231
+end Gerer_Annuaire_Inverse;

+ 2000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A2000.txt
File diff suppressed because it is too large
View File


+ 100
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_100.txt View File

@@ -0,0 +1,100 @@
1
+Christina Salvietti Dunkerque Stomatologue 0614557340
2
+Thomas Dalton Orleans Rhumatologue 0717045284
3
+Michael Hemp Pantin Psychiatre 0789751830
4
+Christopher Chalmers Suresnes Veterinaire 0765856048
5
+Kathrine Hall Tours Radiologue 0723029341
6
+Robin Cook Angers Dermatologue 0771690567
7
+Alexander Seaberry Versailles Veterinaire 0688468848
8
+Lydia Gunter Montrouge Radiologue 0791786318
9
+Ronald Berry Pantin Urologue 0766359222
10
+Ralph Getz Perpignan Pediatre 0736397458
11
+Sarah Venhorst Arles Cardiologue 0718276125
12
+Dorothy Schrenk Dijon Psychiatre 0730529239
13
+Valerie Hill Courbevoie Gynecologue 0740938552
14
+Bethany Hemmingsen Belfort Pharmacien 0661965668
15
+Alex Sircy Carcassonne Dentiste 0767042063
16
+Dawn Orduna Limoges Pharmacien 0729276847
17
+John Roberts Valence Ophtalmologie 0606017296
18
+Kirk Mentzer Beziers Stomatologue 0754938171
19
+Rod Brandes Beauvais Ophtalmologie 0677493599
20
+Ann Collins Drancy Rhumatologue 0728051106
21
+Lyle Lynch Bordeaux Pneumologue 0611081673
22
+Daniel Gaytan Nimes Dentiste 0734320107
23
+Maria Clayton Cayenne Stomatologue 0707951067
24
+Michelle Szaflarski Bourges Rhumatologue 0671359079
25
+Connie Myles Rouen Psychiatre 0670774856
26
+Michelle Koller Angers Orthodontiste 0789861804
27
+Burton Gould Meaux Kinesitherapeute 0759713789
28
+William Downs Metz Urologue 0624420780
29
+Warren Thacker Cannes Pharmacien 0787114057
30
+Gabrielle Atwood Vincennes Kinesitherapeute 0717448326
31
+Nancy Schlemmer Cergy Stomatologue 0680012397
32
+Joshua Sheahan Belfort ORL 0751676741
33
+Janet Matusz Limoges Infirmier 0679596606
34
+June Phillips Frejus Cardiologue 0794575429
35
+Bonnie Henry Bourges Pharmacien 0733255479
36
+Brad Tinajero Niort ORL 0787004064
37
+Diane Brody Paris Stomatologue 0619689557
38
+Andrew Brizuela Perpignan Veterinaire 0725147359
39
+Tiffany Johnson Montpellier Cardiologue 0662233729
40
+Jean Ball Beauvais Psychologue 0619930405
41
+Edwin Womack Pessac Cardiologue 0610446516
42
+Walter Lee Mulhouse Urologue 0736737546
43
+Lionel Garrison Sarcelles Urologue 0626162381
44
+Ted Ross Limoges Dermatologue 0736812823
45
+Joseph Burgos Merignac Dermatologue 0686454461
46
+Helen Rudd Suresnes Rhumatologue 0720159880
47
+John Edwards Colombes Stomatologue 0786816630
48
+Patricia Mckenzie Bayonne Radiologue 0799285175
49
+Barry Washington Carcassonne Gynecologue 0629044930
50
+Brent Rumph Dunkerque Kinesitherapeute 0601686369
51
+Howard Hopper Calais Gynecologue 0736698485
52
+Willie Morber Pessac Pharmacien 0684229819
53
+Debra Ferro Argenteuil Dermatologue 0715229166
54
+Jewell Browne Clamart Infirmier 0613448062
55
+Marjorie Phillips Beziers Dentiste 0626771559
56
+Bobbie Dickson Roubaix Veterinaire 0752944999
57
+Dorothy Taylor Drancy Pneumologue 0727657312
58
+Shelley Toure Albi Ophtalmologie 0728248225
59
+Jacqueline Lowe Lorient Psychologue 0766130683
60
+Thelma Joyce Sartrouville Psychologue 0782053265
61
+Taneka Bonnell Nancy Gynecologue 0708715730
62
+Johnny Verduzco Martigues Dermatologue 0640313570
63
+Lydia Stahnke Perpignan Gynecologue 0654914801
64
+Noel Seng Colmar Pharmacien 0640985650
65
+Patricia Mancia Nantes Pharmacien 0661452251
66
+Andrew Edison Cannes Infirmier 0682646757
67
+George Chan Clichy Pediatre 0704365146
68
+Laura Krajewski Tours Pneumologue 0728727260
69
+Matthew Ringwood Cergy Oncologue 0769681461
70
+Kenneth Cox Sevran Pneumologue 0651190403
71
+Odell Anderson Dijon Dentiste 0644008941
72
+Cynthia Stelling Antony Pneumologue 0709334530
73
+Fred Collins Lyon Psychiatre 0768046535
74
+Robert Rose Paris Dermatologue 0696752326
75
+Ronald Carpenter Tourcoing ORL 0798115523
76
+Carolyn Jordan Montrouge Ophtalmologie 0670251464
77
+Scott Harris Montpellier Orthodontiste 0671519724
78
+John Turner Brest Urologue 0666825542
79
+Arturo Strobel Lorient Veterinaire 0718350189
80
+Mary Byrd Calais ORL 0770391790
81
+Maria Castillo Villejuif Psychiatre 0640320392
82
+Helen Smith Venissieux Cardiologue 0710300526
83
+Elizabeth Runyon Lyon Cardiologue 0754831274
84
+Irma Lebeau Chambery Veterinaire 0622965436
85
+Raul Petrick Orleans Gynecologue 0782714832
86
+Genevieve White Sartrouville Kinesitherapeute 0701551618
87
+Charlotte Allred Lyon Psychologue 0779128443
88
+Ashley Golish Clichy Dermatologue 0733829538
89
+Christopher Marshall Perpignan Pneumologue 0608430736
90
+Patricia Martinez Creteil Urologue 0708675019
91
+Shawn Depue Quimper Urologue 0771007917
92
+James Whitaker Antibes Rhumatologue 0708105493
93
+Venus Heath Merignac Ophtalmologie 0764982294
94
+Henry Taylor Quimper Pediatre 0627414030
95
+Gerald Ward Antony Infirmier 0760432900
96
+Pearlie Wallace Lorient Oncologue 0678446542
97
+Darrell Dingman Aubervilliers Pneumologue 0742554197
98
+John Wingard Vincennes Rhumatologue 0610835804
99
+Regina Mitchell Cergy Kinesitherapeute 0799055623
100
+Amanda Johnson Paris Pharmacien 0783971691

+ 100000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_100000.txt
File diff suppressed because it is too large
View File


+ 150000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_150000.txt
File diff suppressed because it is too large
View File


+ 50000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/A_50000.txt
File diff suppressed because it is too large
View File


+ 100
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_100.txt View File

@@ -0,0 +1,100 @@
1
+Jason Ramirez Cayenne Dermatologue 0601469441
2
+Paul Adkins Clichy Pharmacien 0602268057
3
+Larry White Villeurbanne Pediatre 0604356724
4
+Marcella Boteilho Montpellier Pharmacien 0605224418
5
+Connie Cooksey Tours ORL 0605740643
6
+Cynthia Stammel Vannes Stomatologue 0606069401
7
+Ricky Gaskins Bourges Gynecologue 0607633062
8
+John Casey Quimper Stomatologue 0612865145
9
+Philip Erwin Evry Gynecologue 0614081922
10
+Maria Jacobs Pau Dermatologue 0615785657
11
+Sandra Bartley Grasse Dentiste 0621732897
12
+Edgar Bailie Tours Dermatologue 0624519053
13
+Jake Larkin Colombes Infirmier 0625330358
14
+Eric Harding Antibes Psychiatre 0628149430
15
+Patricia Forrest Orleans Stomatologue 0630153546
16
+Matthew Harriman Frejus Rhumatologue 0630349477
17
+Kelly Randle Metz Pneumologue 0631183761
18
+Robert Quincy Marseille Dermatologue 0631258707
19
+Craig Schwartz Perpignan Rhumatologue 0639863302
20
+Melissa Lawhorn Merignac Pneumologue 0641574403
21
+Kim Hildreth Argenteuil Pediatre 0641908377
22
+Peter Long Nancy Orthodontiste 0642485116
23
+Victoria Bookman Lille Stomatologue 0644959823
24
+Jeffery Clark Montrouge Ophtalmologie 0648294804
25
+Leona Delisi Colombes Psychologue 0649441977
26
+Erika Jessup Argenteuil Infirmier 0650142977
27
+Chi Scoggins Troyes Pediatre 0654342363
28
+William Turner Sartrouville Pediatre 0655203465
29
+Kathy Ramirez Cergy ORL 0656262558
30
+Kathleen Woodruff Arles Veterinaire 0657249252
31
+Harold Redenbaugh Bobigny Kinesitherapeute 0660776057
32
+Eduardo Harper Drancy Pediatre 0661387296
33
+Doris Childs Evry Gynecologue 0662708341
34
+Leslie Sundt Grenoble Rhumatologue 0665241194
35
+Abram Kelly Sarcelles Ophtalmologie 0667282459
36
+Roy Scott Calais Cardiologue 0678927491
37
+Justin Garcia Rennes Dentiste 0681054726
38
+Olga Corvin Clichy Gynecologue 0681846139
39
+Irene Calhoun Villeurbanne Radiologue 0684144734
40
+Jody Johnson Lorient Stomatologue 0684502123
41
+Robert Witham Sarcelles Kinesitherapeute 0686187837
42
+Holly Pruitt Nice Kinesitherapeute 0690423255
43
+Carlos Rison Montauban Dermatologue 0696704526
44
+Keith Mota Limoges Veterinaire 0698170210
45
+Rhonda Irby Carcassonne Kinesitherapeute 0701503627
46
+Debra Simmons Troyes Cardiologue 0703288515
47
+Peter Cox Bobigny Cardiologue 0704332413
48
+Tosha Heinbach Dijon Gynecologue 0705162957
49
+Kenneth Lawrence Nancy Ophtalmologie 0705406371
50
+Daniel Slevin Chambery Rhumatologue 0707151590
51
+Franklin Baker Paris Rhumatologue 0709305684
52
+Sonia Satterwhite Evry Radiologue 0709550131
53
+Geneva Stenn Bordeaux Gynecologue 0710075283
54
+Alice Griffy Nice Orthodontiste 0710934802
55
+Michael Irwin Bayonne Pharmacien 0712350585
56
+David Peterson Nice ORL 0715265740
57
+Monique Johnson Clichy Radiologue 0719342067
58
+Jessie Beaman Pantin Dermatologue 0719417697
59
+Charles Sanyaro Villeurbanne Orthodontiste 0720356493
60
+James Lindsey Chambery Rhumatologue 0721248905
61
+Virginia Allen Rouen Oncologue 0722925021
62
+Samuel Mackillop Annecy Dentiste 0724148510
63
+Timothy Thomas Arles Orthodontiste 0724414755
64
+Joyce Kindrick Frejus Oncologue 0725413006
65
+Freddie Bintner Lorient ORL 0728686818
66
+Bryce Herring Albi Rhumatologue 0732739821
67
+Josephine Whitehurst Pantin Orthodontiste 0734427363
68
+Jessica Francois Amiens Pediatre 0736783189
69
+Patricia Lewis Poitiers ORL 0740644722
70
+Michelle Rosario Marseille Stomatologue 0741537047
71
+Buddy Anderson Grenoble Orthodontiste 0741605824
72
+Ricky Ehrhardt Annecy Gynecologue 0742366068
73
+Derek Ezell Albi Rhumatologue 0743172458
74
+Lorita Standridge Suresnes Urologue 0743287915
75
+Alexandra Tullar Belfort ORL 0744054303
76
+Donna Glover Bayonne Pneumologue 0746300880
77
+Anna Toon Arles Ophtalmologie 0751712965
78
+Chang Ray Colombes Gynecologue 0755354553
79
+Mary Flores Laval Psychologue 0759792709
80
+Alejandrina Gibson Toulon Dentiste 0761143543
81
+Daniel Gross Marseille Gynecologue 0761364927
82
+Frank Lish Cergy Psychiatre 0762411393
83
+Dean Deppe Pessac Psychiatre 0765100432
84
+James Shy Brest Psychologue 0766767527
85
+Julie Anthony Carcassonne Dermatologue 0767409084
86
+Matt Patterson Avignon Rhumatologue 0771974938
87
+Edna Malcolm Villejuif Radiologue 0775564082
88
+Barbara Booth Roubaix Urologue 0775866258
89
+Joanna Hine Quimper Cardiologue 0777867516
90
+Roy Higgins Versailles Radiologue 0777908263
91
+Jose Chandler Vincennes Kinesitherapeute 0778332698
92
+Christine Collins Niort Infirmier 0778787127
93
+Daniel Adkisson Clamart Pneumologue 0779033634
94
+Daryl Swain Paris ORL 0779406882
95
+Belle Scott Laval Dentiste 0782884192
96
+Daniel Carpenter Tours Pneumologue 0785010855
97
+Deborah Ewing Pau Pediatre 0786096527
98
+Michael Long Ajaccio Pediatre 0789814751
99
+Charlie Ortiz Bondy Dentiste 0799036472
100
+Elizabeth Strunk Rennes Psychologue 0799416523

+ 100000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_100000.txt
File diff suppressed because it is too large
View File


+ 150000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_150000.txt
File diff suppressed because it is too large
View File


+ 50000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/B_50000.txt
File diff suppressed because it is too large
View File


+ 10
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/T_10.txt View File

@@ -0,0 +1,10 @@
1
+Charles Chang Beziers ORL 0703888032
2
+Martha Bibbs Beauvais Psychiatre 0616751216
3
+Jerry Joosten Albi Pharmacien 0724258260
4
+Elijah Taylor Caen Orthodontiste 0770222606
5
+Gary Maupin Bayonne Rhumatologue 0705071875
6
+William Snider Tours Radiologue 0621112196
7
+Josefa Eckel Villeurbanne Kinesitherapeute 0784142335
8
+John Brunton Lorient Oncologue 0617519421
9
+Ronald Crank Montreuil Dentiste 0668920050
10
+Joanne Ramos Sevran Veterinaire 0657148529

+ 12
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/perf.sh View File

@@ -0,0 +1,12 @@
1
+#!/bin/bash
2
+
3
+#Permet de créer les fichiers de performance à partir des annuaires
4
+for i in `ls`
5
+do
6
+	if test -f $i
7
+	then
8
+		cat $i | awk '{print $5}' > performance/$i.perf
9
+	fi
10
+	echo "$i done !"
11
+done
12
+echo "done"

+ 100
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_100.txt.perf View File

@@ -0,0 +1,100 @@
1
+0614557340
2
+0717045284
3
+0789751830
4
+0765856048
5
+0723029341
6
+0771690567
7
+0688468848
8
+0791786318
9
+0766359222
10
+0736397458
11
+0718276125
12
+0730529239
13
+0740938552
14
+0661965668
15
+0767042063
16
+0729276847
17
+0606017296
18
+0754938171
19
+0677493599
20
+0728051106
21
+0611081673
22
+0734320107
23
+0707951067
24
+0671359079
25
+0670774856
26
+0789861804
27
+0759713789
28
+0624420780
29
+0787114057
30
+0717448326
31
+0680012397
32
+0751676741
33
+0679596606
34
+0794575429
35
+0733255479
36
+0787004064
37
+0619689557
38
+0725147359
39
+0662233729
40
+0619930405
41
+0610446516
42
+0736737546
43
+0626162381
44
+0736812823
45
+0686454461
46
+0720159880
47
+0786816630
48
+0799285175
49
+0629044930
50
+0601686369
51
+0736698485
52
+0684229819
53
+0715229166
54
+0613448062
55
+0626771559
56
+0752944999
57
+0727657312
58
+0728248225
59
+0766130683
60
+0782053265
61
+0708715730
62
+0640313570
63
+0654914801
64
+0640985650
65
+0661452251
66
+0682646757
67
+0704365146
68
+0728727260
69
+0769681461
70
+0651190403
71
+0644008941
72
+0709334530
73
+0768046535
74
+0696752326
75
+0798115523
76
+0670251464
77
+0671519724
78
+0666825542
79
+0718350189
80
+0770391790
81
+0640320392
82
+0710300526
83
+0754831274
84
+0622965436
85
+0782714832
86
+0701551618
87
+0779128443
88
+0733829538
89
+0608430736
90
+0708675019
91
+0771007917
92
+0708105493
93
+0764982294
94
+0627414030
95
+0760432900
96
+0678446542
97
+0742554197
98
+0610835804
99
+0799055623
100
+0783971691

+ 100000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_100000.txt.perf
File diff suppressed because it is too large
View File


+ 150000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_150000.txt.perf
File diff suppressed because it is too large
View File


+ 50000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/A_50000.txt.perf
File diff suppressed because it is too large
View File


+ 100
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_100.txt.perf View File

@@ -0,0 +1,100 @@
1
+0601469441
2
+0602268057
3
+0604356724
4
+0605224418
5
+0605740643
6
+0606069401
7
+0607633062
8
+0612865145
9
+0614081922
10
+0615785657
11
+0621732897
12
+0624519053
13
+0625330358
14
+0628149430
15
+0630153546
16
+0630349477
17
+0631183761
18
+0631258707
19
+0639863302
20
+0641574403
21
+0641908377
22
+0642485116
23
+0644959823
24
+0648294804
25
+0649441977
26
+0650142977
27
+0654342363
28
+0655203465
29
+0656262558
30
+0657249252
31
+0660776057
32
+0661387296
33
+0662708341
34
+0665241194
35
+0667282459
36
+0678927491
37
+0681054726
38
+0681846139
39
+0684144734
40
+0684502123
41
+0686187837
42
+0690423255
43
+0696704526
44
+0698170210
45
+0701503627
46
+0703288515
47
+0704332413
48
+0705162957
49
+0705406371
50
+0707151590
51
+0709305684
52
+0709550131
53
+0710075283
54
+0710934802
55
+0712350585
56
+0715265740
57
+0719342067
58
+0719417697
59
+0720356493
60
+0721248905
61
+0722925021
62
+0724148510
63
+0724414755
64
+0725413006
65
+0728686818
66
+0732739821
67
+0734427363
68
+0736783189
69
+0740644722
70
+0741537047
71
+0741605824
72
+0742366068
73
+0743172458
74
+0743287915
75
+0744054303
76
+0746300880
77
+0751712965
78
+0755354553
79
+0759792709
80
+0761143543
81
+0761364927
82
+0762411393
83
+0765100432
84
+0766767527
85
+0767409084
86
+0771974938
87
+0775564082
88
+0775866258
89
+0777867516
90
+0777908263
91
+0778332698
92
+0778787127
93
+0779033634
94
+0779406882
95
+0782884192
96
+0785010855
97
+0786096527
98
+0789814751
99
+0799036472
100
+0799416523

+ 100000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_100000.txt.perf
File diff suppressed because it is too large
View File


+ 150000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_150000.txt.perf
File diff suppressed because it is too large
View File


+ 50000
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/B_50000.txt.perf
File diff suppressed because it is too large
View File


+ 10
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/T_10.txt.perf View File

@@ -0,0 +1,10 @@
1
+0703888032
2
+0616751216
3
+0724258260
4
+0770222606
5
+0705071875
6
+0621112196
7
+0784142335
8
+0617519421
9
+0668920050
10
+0657148529

+ 11
- 0
semestre4/TP4_arbres_binaires_genericite/jeux_de_donnees/performance/perf.sh.perf View File

@@ -0,0 +1,11 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+'{print
8
+
9
+
10
+
11
+

+ 184
- 0
semestre4/TP4_arbres_binaires_genericite/liste_ordonnee_cle_g.adb View File

@@ -0,0 +1,184 @@
1
+-- Date : Mars 2015
2
+-- Auteur : MJ. Huguet
3
+-- 
4
+-- Objet : corps liste ordonnee generique
5
+--
6
+-- Remarque : 
7
+--  	les elements disposent d'une cle permettant de les identifier
8
+-----------------------------------------------------------------------------
9
+with Ada.Unchecked_Deallocation;
10
+
11
+package body Liste_Ordonnee_Cle_G is
12
+   
13
+   -----------------------------------------------------------------------------
14
+   -- Definir l'egalite sur des elements comme l'egalite sur la cle
15
+   -- c'est pour blinder la definition d'une cle !!!
16
+   function "="(E1, E2 : Element) return Boolean is
17
+   begin
18
+      return Cle_De(E1)=Cle_De(E2);
19
+   end "=";
20
+   function "<"(E1, E2 : Element) return Boolean is
21
+   begin
22
+      return Cle_De(E1)<Cle_De(E2);
23
+   end "<";
24
+   
25
+   
26
+   -------------------------------------------------------------------------
27
+   function Est_Vide(L : in Une_Liste_Ordonnee) return Boolean is
28
+   begin
29
+      return L.Debut = null;
30
+   end Est_Vide;
31
+   -------------------------------------------------------------------------
32
+
33
+   -------------------------------------------------------------------------
34
+   function Cardinal(L : in Une_Liste_Ordonnee) return Integer is
35
+   begin
36
+      return L.Taille;
37
+   end Cardinal;
38
+   -------------------------------------------------------------------------
39
+
40
+   -----------------------------------------------------------------------------
41
+   -- Appartient classique sur une liste simplement chainee (type Lien) ordonnee
42
+   --    base sur un element
43
+   function Appartient_Lien(E : in Element; LL : in Lien) return Boolean is
44
+      Resultat :boolean;
45
+   begin
46
+      if LL = null or else E < LL.all.Info then
47
+         Resultat := False;         -- element non trouve
48
+      elsif E = LL.all.Info then
49
+         Resultat := True;          -- element trouve en 1ere place
50
+      else
51
+         Resultat := Appartient_Lien(E, LL.all.Suiv);  -- on cherche plus loin
52
+      end if;
53
+      return Resultat;
54
+   end Appartient_Lien;
55
+
56
+   function Appartient(E : in Element; L : in Une_Liste_Ordonnee) return Boolean is
57
+   begin
58
+      return Appartient_Lien(E, L.Debut);
59
+   end Appartient;
60
+   
61
+   --    base sur une cle
62
+   function Appartient_Lien(C : in Key; LL : in Lien) return Boolean is
63
+      Resultat :boolean;
64
+   begin
65
+      if LL = null or else C < Cle_De(LL.all.Info) then
66
+         Resultat := False;         -- element non trouve
67
+      elsif C = Cle_De(LL.all.Info) then
68
+         Resultat := True;          -- element trouve en 1ere place
69
+      else
70
+         Resultat := Appartient_Lien(C, LL.all.Suiv);  -- on cherche plus loin
71
+      end if;
72
+      return Resultat;
73
+   end Appartient_Lien;
74
+
75
+   function Appartient(C : in Key; L : in Une_Liste_Ordonnee) return Boolean is
76
+   begin
77
+      return Appartient_Lien(C, L.Debut);
78
+   end Appartient;
79
+   -------------------------------------------------------------------------
80
+
81
+   -------------------------------------------------------------------------
82
+   -- Conversion en chaine de caracteres
83
+   --
84
+   -- sur le type Lien
85
+
86
+   function Lien_To_String(LL : in Lien) return String is
87
+   begin
88
+      if LL = null then return "";
89
+                   else return Element_To_String(LL.all.info) & Lien_To_String(LL.all.suiv);
90
+      end if;
91
+   end Lien_To_String;
92
+
93
+   -- sur le type Une_Liste_Ordonnee_Entiers
94
+   function Liste_To_String(L: in Une_Liste_Ordonnee) return String is
95
+   begin
96
+      return Integer'Image(L.Taille) & " elements : (" & Lien_To_String(L.Debut) & " )";
97
+   end Liste_To_String;
98
+   -------------------------------------------------------------------------
99
+
100
+   -------------------------------------------------------------------------
101
+   -- Insertion ORDONNEE et SANS DOUBLON
102
+   --    A CORRIGER PAR LES ETUDIANTS (FAIT ICI)
103
+   procedure Inserer_Lien(E: in Element; LL: in out Lien) is
104
+   begin
105
+      if LL=null then
106
+	    LL := new Cellule'(E, LL);
107
+      elsif E < LL.all.Info then
108
+	    -- LL := new Cellule'(E, LL.all.Suiv); 
109
+	    LL:= new Cellule'(E, LL); -- la correction est ici !	
110
+      elsif E=LL.all.Info then
111
+	    raise Element_Deja_Present;
112
+      else
113
+	    Inserer_Lien(E, LL.all.Suiv);
114
+      end if;
115
+   end Inserer_Lien;
116
+
117
+   -------------------------------------------------------------------------
118
+   procedure Inserer(E: in Element; L: in out Une_Liste_Ordonnee) is
119
+   begin
120
+      Inserer_Lien(E, L.Debut);
121
+      L.Taille := L.Taille + 1;
122
+   end Inserer;
123
+   -------------------------------------------------------------------------
124
+
125
+
126
+   -- Instanciation de Ada.Unchecked_Deallocation pour desallouer
127
+   -- la memoire en cas de suppression des elements d'une liste
128
+   -------------------------------------------------------------------------
129
+   procedure Free is new Ada.Unchecked_Deallocation(Cellule, Lien);
130
+   -------------------------------------------------------------------------
131
+   procedure Supprimer_Lien(E : in Element; LL: in out Lien) is
132
+      Recup : Lien;
133
+   begin
134
+      if LL = null or else E < LL.All.Info then
135
+         raise Element_Non_Present;
136
+      elsif E = LL.All.Info then
137
+         Recup := LL;           -- on repere la cellule a recycler
138
+         LL     := LL.All.Suiv;  -- on modifie le debut de la liste
139
+         Free(Recup);          -- on recupere la memoire
140
+      else
141
+         Supprimer_Lien(E, LL.all.suiv);
142
+      end if;
143
+   end Supprimer_Lien;
144
+   -------------------------------------------------------------------------
145
+   procedure Supprimer(E: in Element; L: in out Une_Liste_Ordonnee) is
146
+   begin
147
+      Supprimer_Lien(E, L.debut);
148
+      L.Taille := L.Taille - 1;
149
+   end Supprimer;
150
+   -----------------------------------------------------------------------------
151
+   
152
+   -----------------------------------------------------------------------------
153
+   function Rechercher_Lien(C : in Key; LL : in Lien) return Element is
154
+   begin
155
+      if LL = null or else C < Cle_De(LL.all.Info) then
156
+         raise Element_Non_Present;
157
+      else
158
+         if C = Cle_De(LL.All.Info) then
159
+            return LL.all.Info;
160
+         else
161
+            return Rechercher_Lien(C, LL.All.Suiv);
162
+         end if;
163
+      end if;
164
+   end Rechercher_Lien;
165
+   
166
+   function Rechercher_Par_Cle(C : in Key; L : Une_Liste_Ordonnee) return Element is
167
+   begin
168
+      return Rechercher_Lien(C, L.Debut);
169
+   end Rechercher_Par_Cle;
170
+   -----------------------------------------------------------------------------
171
+  
172
+   procedure Filtrage(L : in Une_Liste_Ordonnee; SL : out Une_Liste_Ordonnee) is
173
+      Aux : Lien := L.Debut;
174
+   begin
175
+      while Aux /= null loop
176
+	 if Selection(Aux.all.Info) then
177
+	    Inserer(Aux.all.Info, SL);
178
+	 end if;
179
+	 Aux := Aux.all.Suiv;
180
+      end loop;
181
+   end Filtrage;
182
+
183
+end Liste_Ordonnee_Cle_G;
184
+

+ 53
- 0
semestre4/TP4_arbres_binaires_genericite/liste_ordonnee_cle_g.ads View File

@@ -0,0 +1,53 @@
1
+-- Date : Mars 2015
2
+-- Auteur : MJ. Huguet
3
+-- 
4
+-- Objet : specification liste ordonnee generique
5
+-- 
6
+-- Remarque : 
7
+--  	les elements disposent d'une cle permettant de les identifier
8
+-----------------------------------------------------------------------------
9
+generic
10
+   type Element is private;
11
+   type Key is private;
12
+   with function Cle_De(E : in Element) return Key;
13
+   with function "<"(C1, C2 : in Key) return Boolean;
14
+   with function "="(C1, C2 : in Key) return Boolean;
15
+   with procedure Free_Element(E : in out Element);
16
+   with function Element_To_String(E : in Element) return String;
17
+   
18
+package Liste_Ordonnee_Cle_G is
19
+   type Une_Liste_Ordonnee is limited private; 
20
+
21
+   Element_Non_Present, Element_Deja_Present : exception;
22
+
23
+   function Est_Vide(L : in Une_Liste_Ordonnee) return Boolean;
24
+   function Cardinal(L : in Une_Liste_Ordonnee) return Integer;
25
+   function Appartient(E : in Element; L : in Une_Liste_Ordonnee) return Boolean;
26
+   function Appartient(C : in Key; L : in Une_Liste_Ordonnee) return Boolean;
27
+   procedure Inserer(E: in Element; L: in out Une_Liste_Ordonnee);
28
+   procedure Supprimer(E: in Element; L: in out Une_Liste_Ordonnee);
29
+   function Liste_To_String(L: in Une_Liste_Ordonnee) return String;
30
+   
31
+   function Rechercher_Par_Cle(C : in Key; L : Une_Liste_Ordonnee) return Element;
32
+   
33
+   generic
34
+      with function Selection(E : in Element) return Boolean;
35
+   procedure Filtrage(L : in Une_Liste_Ordonnee; SL : out Une_Liste_Ordonnee);
36
+   
37
+private
38
+   -- types classiques permettant de realiser des listes simplement chainees
39
+   type Cellule;
40
+   type Lien    is access Cellule;
41
+   type Cellule is record
42
+        Info : Element;
43
+        Suiv : Lien;
44
+   end record;
45
+
46
+   -- type liste ameliore : record contenant la liste et sa taille
47
+   -- (evite de parcourir la liste pour calculer la taille)
48
+
49
+   type Une_Liste_Ordonnee is record
50
+      Debut  : Lien    := null;
51
+      Taille : Natural := 0;
52
+   end record;
53
+end Liste_Ordonnee_Cle_G ;

+ 14
- 0
semestre4/TP4_arbres_binaires_genericite/output_example.txt View File

@@ -0,0 +1,14 @@
1
+Programme d'annuaire inversé - Version ABR
2
+Nom de l'annuaire: 
3
+A_50000.txt
4
+Annuaire en mémoire.
5
+
6
+Veillez saisir un numéro à rechercher: 
7
+0765915625
8
+Recherche de 0765915625 dans l'arbre
9
+Entrée trouvée : Sharon Torres Besançon Psychiatre 0765915625; 
10
+La recherche a durée :  0.000014000
11
+
12
+Recherche dans la liste : 
13
+Entrée trouvée : Sharon Torres Besançon Psychiatre 0765915625; 
14
+La recherche a durée :  0.011632000

+ 9
- 0
semestre4/TP4_arbres_binaires_genericite/pointeurs_de_strings.ads View File

@@ -0,0 +1,9 @@
1
+with Ada.Unchecked_Deallocation;
2
+
3
+package Pointeurs_De_Strings is
4
+	
5
+	type P_String is access String;
6
+
7
+	procedure Liberer_String is new Ada.Unchecked_Deallocation(String , P_String);
8
+
9
+end Pointeurs_De_Strings;

BIN
semestre4/TP4_arbres_binaires_genericite/tester_abr_contacts View File


+ 65
- 0
semestre4/TP4_arbres_binaires_genericite/tester_abr_contacts.adb View File

@@ -0,0 +1,65 @@
1
+with Ada.Text_Io; use Ada.Text_Io;
2
+with Contact_Cle; use Contact_Cle;
3
+with Arbre_Bin_Recherche_Cle_G;
4
+
5
+
6
+procedure Tester_Abr_Contacts is
7
+   
8
+   -- Instanciation du paquetage
9
+   package Arbre_Contacts is new Arbre_Bin_Recherche_Cle_G(Un_Contact, Cle_contact, Cle, "<", "=", Liberer_Contact, Contact_To_string);
10
+   use Arbre_Contacts;
11
+   
12
+   
13
+   -- Variables pour la lecture du fichier annuaire
14
+   Fichier : File_Type;
15
+   Chaine, Ligne : String(1..80);
16
+   Len, last : Integer := 0;
17
+   AB : Arbre;
18
+   C : Un_Contact;
19
+
20
+   Prenom, Nom, Ville, Specia, Telephone, Fin, I : Integer := 0;
21
+begin
22
+   
23
+   -----------------------------------------------------------
24
+   -- Utilisation d'annuaires
25
+   -----------------------------------------------------------
26
+   
27
+   -- Entourloupe pour avoir un nom de fichier contraint, saisi par l'utilisateur et de bonne taille
28
+   Put_Line("Lecture d'un fichier de contact, veillez saisir le nom du fichier : ");
29
+   Get_Line(Chaine, Len);
30
+   declare
31
+      Nom_Fichier : String(Chaine'First..Len) := Chaine(Chaine'First..Len);
32
+   begin
33
+      open(Fichier, in_File, "./jeux_de_donnees/" & Nom_Fichier);
34
+      while not End_Of_File(Fichier) loop
35
+	 Get_Line (Fichier,  Ligne ,  Len ) ; 
36
+	 Put_Line ( "Ajouté à l'arbre: " & Ligne(1..Len));
37
+	 
38
+	 Prenom := 1;
39
+	 Nom := 0;
40
+	 Ville := 0;
41
+	 Specia := 0;
42
+	 Telephone := 0;
43
+	 Fin := 0;
44
+	 I := 1;
45
+	 
46
+	 while Telephone = 0 loop
47
+	    if Ligne(I) = ' ' then
48
+	       if Nom = 0 then Nom := I;
49
+	       elsif Ville = 0 then Ville := I;
50
+	       elsif Specia = 0 then Specia := I;
51
+	       elsif Telephone = 0 then Telephone := I; Fin := Telephone + 10; 
52
+	       end if;
53
+	    end if;
54
+	    I := I + 1;
55
+	 end loop;
56
+	 C := Creer_Contact(Ligne(Prenom..Nom-1), Ligne(Nom+1..Ville-1), Ligne(Ville+1..Specia-1), Ligne(Specia+1..Telephone-1), Ligne(Telephone+1..Fin-1) & " ");
57
+	 Inserer(C, AB);
58
+      end loop;
59
+      Close(Fichier);
60
+      
61
+      
62
+      Put_Line(Arbre_To_String(AB));
63
+      end;
64
+   
65
+end Tester_Abr_Contacts;

+ 0
- 0
semestre4/TP4_arbres_binaires_genericite/tester_abr_entiers View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save