diff --git a/DEV3.2/Files/chaine/LinkedQueue$Node.class b/DEV3.2/Files/chaine/LinkedQueue$Node.class new file mode 100644 index 0000000..0c53952 Binary files /dev/null and b/DEV3.2/Files/chaine/LinkedQueue$Node.class differ diff --git a/DEV3.2/Files/tableau/Arithmetique.class b/DEV3.2/Files/tableau/Arithmetique.class new file mode 100644 index 0000000..425fcb8 Binary files /dev/null and b/DEV3.2/Files/tableau/Arithmetique.class differ diff --git a/DEV3.2/Files/tableau/Arithmetique.java b/DEV3.2/Files/tableau/Arithmetique.java new file mode 100644 index 0000000..feab2e3 --- /dev/null +++ b/DEV3.2/Files/tableau/Arithmetique.java @@ -0,0 +1,56 @@ +public class Arithmetique { + + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Veuillez fournir une expression en notation polonaise inversée."); + return; + } + + // Utilisation de l'implémentation FileTableau pour la file + File queue = new FileTableau<>(); + + try { + for (String token : args) { + switch (token) { + case "+": + // Addition + queue.ajouter(queue.retirer() + queue.retirer()); + break; + case "-": + // Soustraction (attention à l'ordre) + int b = queue.retirer(); + int a = queue.retirer(); + queue.ajouter(a - b); + break; + case "x": + // Multiplication + queue.ajouter(queue.retirer() * queue.retirer()); + break; + case "/": + // Division (attention à l'ordre) + b = queue.retirer(); + a = queue.retirer(); + if (b == 0) { + throw new ArithmeticException("Division par zéro"); + } + queue.ajouter(a / b); + break; + default: + // Si ce n'est pas un opérateur, alors c'est un nombre + queue.ajouter(Integer.parseInt(token)); + break; + } + } + + // Le résultat final doit être le seul élément restant dans la file + if (queue.taille() == 1) { + System.out.println("= " + queue.retirer()); + } else { + System.out.println("Erreur : Expression incorrecte."); + } + + } catch (Exception e) { + System.out.println("Erreur lors de l'évaluation de l'expression : " + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/DEV3.2/Files/tableau/File.class b/DEV3.2/Files/tableau/File.class new file mode 100644 index 0000000..42ef4dd Binary files /dev/null and b/DEV3.2/Files/tableau/File.class differ diff --git a/DEV3.2/Files/tableau/File.java b/DEV3.2/Files/tableau/File.java new file mode 100644 index 0000000..f0452b1 --- /dev/null +++ b/DEV3.2/Files/tableau/File.java @@ -0,0 +1,6 @@ +public interface File { + void ajouter(E element); // Ajoute un élément en fin de la file + E retirer(); // Retire et retourne l'élément en tête de la file + int taille(); // Retourne la taille de la file + boolean estVide(); // Vérifie si la file est vide +} \ No newline at end of file diff --git a/DEV3.2/Files/tableau/FileTableau.class b/DEV3.2/Files/tableau/FileTableau.class new file mode 100644 index 0000000..7b9c119 Binary files /dev/null and b/DEV3.2/Files/tableau/FileTableau.class differ diff --git a/DEV3.2/Files/tableau/FileTableau.java b/DEV3.2/Files/tableau/FileTableau.java new file mode 100644 index 0000000..ff237f8 --- /dev/null +++ b/DEV3.2/Files/tableau/FileTableau.java @@ -0,0 +1,41 @@ +public class FileTableau implements File { + private static final int CAPACITE_INITIALE = 20; + private E[] elements; + private int taille = 0; + private int debut = 0; + private int fin = 0; + + @SuppressWarnings("unchecked") + public FileTableau() { + elements = (E[]) new Object[CAPACITE_INITIALE]; // Création du tableau initial + } + + @Override + public void ajouter(E element) { + elements[fin] = element; + fin = (fin + 1); + taille++; + } + + @Override + public E retirer() { + if (estVide()) { + throw new IllegalStateException("La file est vide"); + } + E element = elements[debut]; + elements[debut] = null; // Supprime la référence pour éviter les fuites de mémoire + debut = (debut + 1); + taille--; + return element; + } + + @Override + public int taille() { + return taille; + } + + @Override + public boolean estVide() { + return taille == 0; + } +} \ No newline at end of file diff --git a/DEV3.2/arbre_suite/Authentification/auth_API/Authentification.class b/DEV3.2/arbre_suite/Authentification/auth_API/Authentification.class new file mode 100644 index 0000000..702cc0b Binary files /dev/null and b/DEV3.2/arbre_suite/Authentification/auth_API/Authentification.class differ diff --git a/DEV3.2/arbre_suite/Authentification/auth_API/Authentification.java b/DEV3.2/arbre_suite/Authentification/auth_API/Authentification.java new file mode 100644 index 0000000..461a085 --- /dev/null +++ b/DEV3.2/arbre_suite/Authentification/auth_API/Authentification.java @@ -0,0 +1,87 @@ +import java.util.HashMap; +import java.util.Scanner; + +public class Authentification { + // Dictionnaire pour stocker les identifiants et mots de passe + private HashMap users; + + public Authentification() { + users = new HashMap<>(); + } + + // Ajout d'un utilisateur + public void addUser(String username, String password) { + if (users.containsKey(username)) { + System.out.println("Utilisateur \"" + username + "\" existe déjà."); + } else { + users.put(username, password); + System.out.println("Utilisateur \"" + username + "\" ajouté"); + } + } + + // Suppression d'un utilisateur + public void removeUser(String username) { + if (users.remove(username) != null) { + System.out.println("Utilisateur \"" + username + "\" retiré"); + } else { + System.out.println("Utilisateur \"" + username + "\" non trouvé."); + } + } + + // Authentification d'un utilisateur + public void authenticate(String username, String password) { + if (users.containsKey(username) && users.get(username).equals(password)) { + System.out.println("Utilisateur \"" + username + "\" reconnu"); + } else { + System.out.println("Utilisateur \"" + username + "\" non reconnu"); + } + } + + // Main pour interagir avec le programme + public static void main(String[] args) { + Authentification auth = new Authentification(); + Scanner scanner = new Scanner(System.in); + + while (true) { + System.out.print("> "); + String command = scanner.nextLine(); + String[] parts = command.split(" "); + + if (parts.length == 0) continue; + + switch (parts[0].toLowerCase()) { + case "add": + if (parts.length == 3) { + auth.addUser(parts[1], parts[2]); + } else { + System.out.println("Usage : add "); + } + break; + + case "del": + if (parts.length == 2) { + auth.removeUser(parts[1]); + } else { + System.out.println("Usage : del "); + } + break; + + case "auth": + if (parts.length == 3) { + auth.authenticate(parts[1], parts[2]); + } else { + System.out.println("Usage : auth "); + } + break; + + case "quit": + System.out.println("Au revoir"); + scanner.close(); + return; + + default: + System.out.println("Commande non reconnue."); + } + } + } +} diff --git a/DEV3.2/arbre_suite/Authentification/auth_sans_API/Authentification.class b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Authentification.class new file mode 100644 index 0000000..98e09d8 Binary files /dev/null and b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Authentification.class differ diff --git a/DEV3.2/arbre_suite/Authentification/auth_sans_API/Authentification.java b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Authentification.java new file mode 100644 index 0000000..82e5846 --- /dev/null +++ b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Authentification.java @@ -0,0 +1,140 @@ +import java.util.Scanner; + +public class Authentification { + + private Node root; + + // Ajouter un utilisateur + public void addUser(String username, String password) { + root = addUserRec(root, username, password); + System.out.println("Utilisateur \"" + username + "\" ajouté"); + } + + private Node addUserRec(Node node, String username, String password) { + if (node == null) { + return new Node(username, password); + } + if (username.compareTo(node.username) < 0) { + node.left = addUserRec(node.left, username, password); + } else if (username.compareTo(node.username) > 0) { + node.right = addUserRec(node.right, username, password); + } else { + node.password = password; // Mise à jour du mot de passe si utilisateur existe + } + return node; + } + + // Supprimer un utilisateur + public void removeUser(String username) { + root = removeUserRec(root, username); + } + + private Node removeUserRec(Node node, String username) { + if (node == null) { + System.out.println("Utilisateur \"" + username + "\" non trouvé."); + return null; + } + + if (username.compareTo(node.username) < 0) { + node.left = removeUserRec(node.left, username); + } else if (username.compareTo(node.username) > 0) { + node.right = removeUserRec(node.right, username); + } else { + // Cas où l'utilisateur est trouvé + if (node.left == null){ + System.out.println("Utilisateur \"" + username + "\" retiré"); + return node.right; + } + if (node.right == null){ + System.out.println("Utilisateur \"" + username + "\" retiré"); + return node.left; + } + + // Remplacer par le successeur in-order + Node minNode = findMin(node.right); + node.username = minNode.username; + node.password = minNode.password; + node.right = removeUserRec(node.right, minNode.username); + } + System.out.println("Utilisateur \"" + username + "\" retiré"); + return node; + } + + private Node findMin(Node node) { + while (node.left != null) { + node = node.left; + } + return node; + } + + // Authentification d’un utilisateur + public void authenticate(String username, String password) { + Node user = findUser(root, username); + if (user != null && user.password.equals(password)) { + System.out.println("Utilisateur \"" + username + "\" reconnu"); + } else { + System.out.println("Utilisateur \"" + username + "\" non reconnu"); + } + } + + private Node findUser(Node node, String username) { + if (node == null){ + return null; + } + if (username.equals(node.username)){ + return node; + } + if (username.compareTo(node.username) < 0) { + return findUser(node.left, username); + } + return findUser(node.right, username); + } + + // Main pour le test + public static void main(String[] args) { + Authentification auth = new Authentification(); + Scanner scanner = new Scanner(System.in); + + while (true) { + System.out.print("> "); + String command = scanner.nextLine(); + String[] parts = command.split(" "); + + if (parts.length == 0) continue; + + switch (parts[0].toLowerCase()) { + case "add": + if (parts.length == 3) { + auth.addUser(parts[1], parts[2]); + } else { + System.out.println("Usage : add "); + } + break; + + case "del": + if (parts.length == 2) { + auth.removeUser(parts[1]); + } else { + System.out.println("Usage : del "); + } + break; + + case "auth": + if (parts.length == 3) { + auth.authenticate(parts[1], parts[2]); + } else { + System.out.println("Usage : auth "); + } + break; + + case "quit": + System.out.println("Au revoir"); + scanner.close(); + return; + + default: + System.out.println("Commande non reconnue."); + } + } + } +} diff --git a/DEV3.2/arbre_suite/Authentification/auth_sans_API/Node.class b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Node.class new file mode 100644 index 0000000..1fef2be Binary files /dev/null and b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Node.class differ diff --git a/DEV3.2/arbre_suite/Authentification/auth_sans_API/Node.java b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Node.java new file mode 100644 index 0000000..767ba41 --- /dev/null +++ b/DEV3.2/arbre_suite/Authentification/auth_sans_API/Node.java @@ -0,0 +1,11 @@ +// Classe interne pour représenter un nœud de l'arbre +public class Node { + String username; + String password; + Node left, right; + + Node(String username, String password) { + this.username = username; + this.password = password; + } +} \ No newline at end of file diff --git a/DEV3.2/arbre_suite/Tri/BinarySearchTree.class b/DEV3.2/arbre_suite/Tri/BinarySearchTree.class new file mode 100644 index 0000000..45f48fc Binary files /dev/null and b/DEV3.2/arbre_suite/Tri/BinarySearchTree.class differ diff --git a/DEV3.2/arbre_suite/Tri/BinarySearchTree.java b/DEV3.2/arbre_suite/Tri/BinarySearchTree.java new file mode 100644 index 0000000..15eae35 --- /dev/null +++ b/DEV3.2/arbre_suite/Tri/BinarySearchTree.java @@ -0,0 +1,67 @@ +import java.util.ArrayList; +import java.util.List; + +public class BinarySearchTree { + + private Node root; // Racine de l'arbre + + // Méthode d'insertion + public void insert(double value) { + root = insertRec(root, value); + } + + private Node insertRec(Node node, double value) { + if (node == null) { + return new Node(value); + } + if (value < node.value) { + node.left = insertRec(node.left, value); + } else if (value > node.value) { + node.right = insertRec(node.right, value); + } + return node; + } + + // Parcours en ordre croissant + public List inOrderTraversal() { + List sortedList = new ArrayList<>(); + inOrderRec(root, sortedList); + return sortedList; + } + + private void inOrderRec(Node node, List sortedList) { + if (node != null) { + inOrderRec(node.left, sortedList); + sortedList.add(node.value); + inOrderRec(node.right, sortedList); + } + } + + // Redéfinir la méthode toString pour afficher les éléments triés + @Override + public String toString() { + return inOrderTraversal().toString(); + } + + // Main pour le test + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Veuillez fournir une liste de réels en ligne de commande."); + return; + } + + // Créer un arbre binaire de recherche et y insérer les éléments + BinarySearchTree bst = new BinarySearchTree(); + for (String arg : args) { + try { + double value = Double.parseDouble(arg); + bst.insert(value); + } catch (NumberFormatException e) { + System.out.println("Valeur invalide ignorée : " + arg); + } + } + + // Afficher les éléments triés + System.out.println("Éléments triés : " + bst); + } +} diff --git a/DEV3.2/arbre_suite/Tri/Node.class b/DEV3.2/arbre_suite/Tri/Node.class new file mode 100644 index 0000000..1a1e7ea Binary files /dev/null and b/DEV3.2/arbre_suite/Tri/Node.class differ diff --git a/DEV3.2/arbre_suite/Tri/Node.java b/DEV3.2/arbre_suite/Tri/Node.java new file mode 100644 index 0000000..e768c83 --- /dev/null +++ b/DEV3.2/arbre_suite/Tri/Node.java @@ -0,0 +1,9 @@ +// Classe interne représentant un nœud +public class Node { + double value; + Node left, right; + + Node(double value) { + this.value = value; + } +} \ No newline at end of file