diff --git a/TD02/code/Pile.py b/TD02/code/Pile.py new file mode 100644 index 0000000000000000000000000000000000000000..90754b41c0f74bb13f938d2785195e8b6b15f80c --- /dev/null +++ b/TD02/code/Pile.py @@ -0,0 +1,20 @@ +class Pile(): + def __init__(self, values = []): + self.__values = [] + for v in values: + self.ajoute(v) + + def ajoute(self, v): + self.__values.append(v) + return v + + def supprime(self): + v = self.__values.pop() + return v + + def affiche(self): + for v in self.__values: + print(v) + + def taille(self): + return len(self.__values) \ No newline at end of file diff --git a/TD02/code/etudiants-large100.txt b/TD02/code/etudiants-large100.txt new file mode 100644 index 0000000000000000000000000000000000000000..03925833d38d9c5cd64cd34eb58983876c21ce11 --- /dev/null +++ b/TD02/code/etudiants-large100.txt @@ -0,0 +1,101 @@ +nom;prenom;filiere;moyenne;absences +Dickerson;Chaney;PSI;6;4 +King;Shay;PSI;2;2 +Chan;Aileen;MP;8;3 +Schwartz;Destiny;PSI;16;5 +Parrish;Prescott;MP;1;4 +Calhoun;Brenda;PSI;10;4 +Watts;Shellie;PSI;6;4 +Baird;Octavius;PC;4;2 +Graves;Vanna;MP;10;0 +Decker;Nerea;PSI;9;4 +Townsend;Naomi;PC;13;3 +Decker;Nichole;PSI;10;3 +Mcgee;Blythe;PSI;7;0 +Franco;Cyrus;PSI;12;1 +Mcdowell;Zelda;MP;6;1 +Cherry;Stone;PSI;10;5 +Mendoza;Kirsten;PC;18;0 +Mathis;Xaviera;MP;12;1 +Booker;Gretchen;MP;2;1 +Hansen;Slade;PSI;1;1 +Mason;Forrest;MP;13;3 +Wolfe;Fatima;PC;15;5 +Richards;Justine;MP;20;0 +Kelley;Abra;PC;2;4 +Lang;Ulysses;PSI;2;5 +Barker;Austin;MP;15;5 +Cannon;Kalia;MP;3;4 +Higgins;Charity;PSI;18;5 +Parker;Fritz;PC;14;2 +Chambers;Yvette;PSI;7;1 +Vinson;Denise;PSI;3;5 +Mcmillan;Chava;PSI;7;3 +Gallegos;Lee;PC;16;0 +Ferguson;Solomon;PSI;11;4 +Camacho;Zena;MP;4;4 +Sexton;Fallon;PSI;16;2 +Campbell;Preston;PC;0;0 +Greer;Lance;PC;15;5 +Oliver;Aileen;PC;10;2 +Nielsen;Timon;PC;1;2 +Perkins;Roth;PSI;1;2 +Beard;Blair;PSI;13;1 +Burgess;Keely;PSI;4;4 +Wells;Honorato;PSI;17;0 +Richardson;Cherokee;PC;20;1 +Burgess;Blair;PC;16;4 +Rice;Florence;PC;7;4 +Villarreal;Delilah;MP;9;5 +Cherry;Maite;MP;0;2 +Berry;Jermaine;MP;17;4 +Shepherd;Alfreda;PSI;20;5 +Workman;April;PC;3;1 +Carter;Herman;PC;11;1 +Carpenter;Teagan;MP;0;1 +Fowler;Leo;PSI;19;4 +Mcgee;Kristen;PSI;9;4 +Mcpherson;Channing;PC;0;0 +Diaz;Nathaniel;PC;4;5 +Klein;Maisie;PSI;16;3 +Graham;Gary;MP;12;4 +Jensen;Raja;PC;18;1 +Wilkinson;Sawyer;PSI;10;0 +Wagner;Lamar;MP;16;2 +Abbott;Sybil;MP;17;1 +Glenn;Arsenio;PSI;4;3 +Moreno;Axel;PSI;7;4 +Barrett;Dylan;PC;14;4 +Keith;Rae;PC;9;1 +Shepard;Rebecca;PC;8;5 +Meyers;Illiana;MP;3;3 +Bruce;Tatyana;MP;2;0 +Mcguire;Olivia;PC;17;4 +Merritt;Tatiana;PSI;19;3 +Berg;Dale;MP;12;1 +Matthews;Tallulah;MP;5;3 +Steele;Cain;MP;8;2 +Ellison;Britanni;PC;4;1 +Richards;Audra;MP;15;0 +Hood;Rylee;PSI;1;4 +Townsend;Paul;PC;14;4 +Cervantes;Thaddeus;MP;10;5 +Dudley;Amela;PC;2;0 +Lucas;Matthew;MP;4;1 +Parrish;Nell;PC;13;3 +Patterson;Bertha;PSI;18;0 +Knapp;Lawrence;MP;3;5 +Stanton;Keith;MP;5;2 +Hayes;Mannix;PSI;3;2 +Pearson;Ross;PC;10;4 +Kaufman;Uta;MP;10;4 +Bauer;Naida;PC;20;5 +Carrillo;Quamar;PC;15;3 +Orr;Lisandra;PSI;6;2 +Randolph;Darryl;PSI;16;4 +Boyer;Prescott;PC;20;2 +Serrano;Ashely;PSI;10;2 +Carney;Oren;PC;7;4 +Riley;Arden;PC;1;5 +Phillips;Joshua;PSI;20;3 +Soto;Colt;PC;16;3 \ No newline at end of file diff --git a/TD02/code/etudiants.txt b/TD02/code/etudiants.txt new file mode 100644 index 0000000000000000000000000000000000000000..12151c39224809a6186b94c0d80b33cf9d929d21 --- /dev/null +++ b/TD02/code/etudiants.txt @@ -0,0 +1,6 @@ +nom;prenom;filiere;note;absences +Dupond;Pierre;MP;19;7 +Dupond;Jeanne;MP;19;5 +Clavier;Christian;PSI;14;1 +Gilles;Eric;PC;16;3 +Arthaud;Nathalie;MP;15;0 \ No newline at end of file diff --git a/TD02/code/load.py b/TD02/code/load.py new file mode 100644 index 0000000000000000000000000000000000000000..0e10d85477875b2d7821f44428c44c7de5cdec36 --- /dev/null +++ b/TD02/code/load.py @@ -0,0 +1,12 @@ +data = [] + +with open("etudiants.txt") as f: + keys = None + for line in f: + l = [w.strip() for w in line.split(';')] + if keys is None: + keys = l + else: + data.append({k:v for k, v in zip(keys, l)}) + +print(data) \ No newline at end of file diff --git a/TD02/code/selection.py b/TD02/code/selection.py new file mode 100644 index 0000000000000000000000000000000000000000..74fdbee7bb62f534392746f550706be491bb5ed0 --- /dev/null +++ b/TD02/code/selection.py @@ -0,0 +1,20 @@ +def selectionSort(l: list = []) -> list: + """Tri par selection en ligne""" + for i in range(0, len(l)): + min = i + for j in range(i+1, len(l)): + if(l[j] < l[min]): + min = j + tmp = l[i] + l[i] = l[min] + l[min] = tmp + + return l + +if __name__=="__main__": + liste = [54,26,93,17,77,31,44,55,20] + + assert(sorted(liste) == selectionSort(liste.copy())) + assert([] == selectionSort([])) + assert([1] == selectionSort([1])) + assert([1, 1] == selectionSort([1, 1])) \ No newline at end of file diff --git a/TD02/code/test_analyse_simple.py b/TD02/code/test_analyse_simple.py new file mode 100644 index 0000000000000000000000000000000000000000..6c86d81ba5499f3ed4f4cf5915aae4b45f8938eb --- /dev/null +++ b/TD02/code/test_analyse_simple.py @@ -0,0 +1,37 @@ +import time +import random +import matplotlib.pyplot as plt + +nvalues = [100, 500, 1500, 2000, 2500, 3000] + +timesSorted = [] +timesSort = [] + +for i in nvalues: + + random.seed() + p = 12**2 + liste = [] + + for x in range(i): liste.append(random.randint(0, p)) + + c = liste.copy() + a=time.perf_counter() + triSorted = sorted(c) + b=time.perf_counter() + timesSorted.append(b-a) + + c = liste.copy() + a=time.perf_counter() + triSort = c + triSort.sort() + b=time.perf_counter() + timesSort.append(b-a) + +plt.plot(nvalues, timesSorted, "g-", label="Tri 1") +plt.plot(nvalues, timesSort, "b-", label="Tri 2") +plt.xlabel("Taille du jeu de données") +plt.ylabel("Temps") +plt.legend(loc="upper left") +plt.title("Comparaison des performances des algorithmes de tri") +plt.show() \ No newline at end of file diff --git a/TD02/code/test_heap.py b/TD02/code/test_heap.py new file mode 100644 index 0000000000000000000000000000000000000000..5514c098c8452628f127ff6ff3f9582da3dd258b --- /dev/null +++ b/TD02/code/test_heap.py @@ -0,0 +1,9 @@ +import heapq +tas = [] + +for i in range(5): heapq.heappush(tas, i) + +while not len(tas) == 0: + print(heapq.heappop(tas), end=" ") + +# 0 1 2 3 4 \ No newline at end of file diff --git a/TD02/code/test_lifoqueue.py b/TD02/code/test_lifoqueue.py new file mode 100644 index 0000000000000000000000000000000000000000..09a4716f4c404fab7429b09349745dd1347e7557 --- /dev/null +++ b/TD02/code/test_lifoqueue.py @@ -0,0 +1,9 @@ +import queue +pile = queue.LifoQueue() + +for i in range(5): pile.put(i) + +while not pile.empty(): + print(pile.get(), end=" ") + +# 4 3 2 1 0 \ No newline at end of file diff --git a/TD02/code/test_pile.py b/TD02/code/test_pile.py new file mode 100644 index 0000000000000000000000000000000000000000..96c377a3a6d62d2b14be0eff4d26b8693166cba1 --- /dev/null +++ b/TD02/code/test_pile.py @@ -0,0 +1,9 @@ +from pile import * + +p = Pile() + +for d in data: + p.ajoute(d) + e = p.supprime() + +print(e['nom'] + " " + e['prenom']) # Arthaud Nathalie \ No newline at end of file diff --git a/TD02/td2.pdf b/TD02/td2.pdf new file mode 100755 index 0000000000000000000000000000000000000000..a62b663c83166f770b5fd7ade6758f0c8cbd76d4 Binary files /dev/null and b/TD02/td2.pdf differ