diff --git a/DEV3.2/TP04/01_Arithmetique/Main.class b/DEV3.2/TP04/01_Arithmetique/Main.class new file mode 100644 index 0000000..d5a5bca Binary files /dev/null and b/DEV3.2/TP04/01_Arithmetique/Main.class differ diff --git a/DEV3.2/TP04/01_Arithmetique/Main.java b/DEV3.2/TP04/01_Arithmetique/Main.java new file mode 100644 index 0000000..fd96efc --- /dev/null +++ b/DEV3.2/TP04/01_Arithmetique/Main.java @@ -0,0 +1,38 @@ +import java.awt.*; +import java.util.ArrayDeque; + +public class Main { + public static void main(String[] args) { + ArrayDeque pile = new ArrayDeque<>(args.length); + + for (int i = 0; i != args.length; i++) { + try { + Integer.parseInt(args[i]); + pile.addFirst(args[i]); + } catch (NumberFormatException e) { + int n2 = Integer.parseInt(pile.removeFirst()); + int n1 = Integer.parseInt(pile.removeFirst()); + System.out.println(n2); + System.out.println(n1); + + switch (args[i]) { + case "+": + pile.addFirst(n1 + n2 + ""); + break; + case "-": + pile.addFirst(n1 - n2 + ""); + break; + case "x": + pile.addFirst(n1 * n2 + ""); + break; + case "/": + pile.addFirst(n1 / n2 + ""); + } + } + } + + System.out.println("= " + pile.removeFirst()); + + + } +} \ No newline at end of file diff --git a/DEV3.2/TP04/02_Chaine/Main.class b/DEV3.2/TP04/02_Chaine/Main.class new file mode 100644 index 0000000..a170e67 Binary files /dev/null and b/DEV3.2/TP04/02_Chaine/Main.class differ diff --git a/DEV3.2/TP04/02_Chaine/Main.java b/DEV3.2/TP04/02_Chaine/Main.java new file mode 100644 index 0000000..86bf148 --- /dev/null +++ b/DEV3.2/TP04/02_Chaine/Main.java @@ -0,0 +1,37 @@ +import java.awt.*; + +public class Main { + public static void main(String[] args) { + PileChainee pile = new PileChainee<>(); + + for (int i = 0; i != args.length; i++) { + try { + Integer.parseInt(args[i]); + pile.addFirst(args[i]); + } catch (NumberFormatException e) { + int n2 = Integer.parseInt(pile.removeFirst()); + int n1 = Integer.parseInt(pile.removeFirst()); + System.out.println(n2); + System.out.println(n1); + + switch (args[i]) { + case "+": + pile.addFirst(n1 + n2 + ""); + break; + case "-": + pile.addFirst(n1 - n2 + ""); + break; + case "x": + pile.addFirst(n1 * n2 + ""); + break; + case "/": + pile.addFirst(n1 / n2 + ""); + } + } + } + + System.out.println("= " + pile.removeFirst()); + + + } +} \ No newline at end of file diff --git a/DEV3.2/TP04/02_Chaine/Pile.class b/DEV3.2/TP04/02_Chaine/Pile.class new file mode 100644 index 0000000..18489eb Binary files /dev/null and b/DEV3.2/TP04/02_Chaine/Pile.class differ diff --git a/DEV3.2/TP04/02_Chaine/Pile.java b/DEV3.2/TP04/02_Chaine/Pile.java new file mode 100644 index 0000000..9445b47 --- /dev/null +++ b/DEV3.2/TP04/02_Chaine/Pile.java @@ -0,0 +1,6 @@ +public interface Pile { + + void addFirst(E element); + E removeFirst(); + boolean isEmpty(); +} \ No newline at end of file diff --git a/DEV3.2/TP04/02_Chaine/PileChainee.class b/DEV3.2/TP04/02_Chaine/PileChainee.class new file mode 100644 index 0000000..8b631ad Binary files /dev/null and b/DEV3.2/TP04/02_Chaine/PileChainee.class differ diff --git a/DEV3.2/TP04/02_Chaine/PileChainee.java b/DEV3.2/TP04/02_Chaine/PileChainee.java new file mode 100644 index 0000000..4151329 --- /dev/null +++ b/DEV3.2/TP04/02_Chaine/PileChainee.java @@ -0,0 +1,52 @@ +public class PileChainee implements Pile { + + protected E valeur; + protected PileChainee suivant; + + public PileChainee() { + this.valeur = null; + this.suivant = null; + } + + public PileChainee(E element) { + this.valeur = element; + this.suivant = null; + } + + @Override + public void addFirst(E element) { + if (this.isEmpty()) { + this.valeur = element; + } else { + PileChainee nouveau = new PileChainee<>(); + nouveau.valeur = this.valeur; + nouveau.suivant = this.suivant; + this.valeur = element; + this.suivant = nouveau; + } + } + + @Override + public E removeFirst() { + if (this.isEmpty()) { + throw new IllegalStateException("Pile vide"); + } else { + if (this.suivant == null) { + E temp = this.valeur; + this.valeur = null; + return temp; + } else { + E temp = this.valeur; + this.valeur = this.suivant.valeur; + this.suivant = this.suivant.suivant; + return temp; + } + } + } + + @Override + public boolean isEmpty() { + return (this.valeur == null); + } + +} \ No newline at end of file diff --git a/DEV3.2/TP04/03_Tableau/Main.class b/DEV3.2/TP04/03_Tableau/Main.class new file mode 100644 index 0000000..b281072 Binary files /dev/null and b/DEV3.2/TP04/03_Tableau/Main.class differ diff --git a/DEV3.2/TP04/03_Tableau/Main.java b/DEV3.2/TP04/03_Tableau/Main.java new file mode 100644 index 0000000..664b807 --- /dev/null +++ b/DEV3.2/TP04/03_Tableau/Main.java @@ -0,0 +1,37 @@ +import java.awt.*; + +public class Main { + public static void main(String[] args) { + PileTableau pile = new PileTableau<>(); + + for (int i = 0; i != args.length; i++) { + try { + Integer.parseInt(args[i]); + pile.addFirst(args[i]); + } catch (NumberFormatException e) { + int n2 = Integer.parseInt(pile.removeFirst()); + int n1 = Integer.parseInt(pile.removeFirst()); + System.out.println(n2); + System.out.println(n1); + + switch (args[i]) { + case "+": + pile.addFirst(n1 + n2 + ""); + break; + case "-": + pile.addFirst(n1 - n2 + ""); + break; + case "x": + pile.addFirst(n1 * n2 + ""); + break; + case "/": + pile.addFirst(n1 / n2 + ""); + } + } + } + + System.out.println("= " + pile.removeFirst()); + + + } +} \ No newline at end of file diff --git a/DEV3.2/TP04/03_Tableau/Pile.class b/DEV3.2/TP04/03_Tableau/Pile.class new file mode 100644 index 0000000..18489eb Binary files /dev/null and b/DEV3.2/TP04/03_Tableau/Pile.class differ diff --git a/DEV3.2/TP04/03_Tableau/Pile.java b/DEV3.2/TP04/03_Tableau/Pile.java new file mode 100644 index 0000000..9445b47 --- /dev/null +++ b/DEV3.2/TP04/03_Tableau/Pile.java @@ -0,0 +1,6 @@ +public interface Pile { + + void addFirst(E element); + E removeFirst(); + boolean isEmpty(); +} \ No newline at end of file diff --git a/DEV3.2/TP04/03_Tableau/PileTableau.class b/DEV3.2/TP04/03_Tableau/PileTableau.class new file mode 100644 index 0000000..c8da2a9 Binary files /dev/null and b/DEV3.2/TP04/03_Tableau/PileTableau.class differ diff --git a/DEV3.2/TP04/03_Tableau/PileTableau.java b/DEV3.2/TP04/03_Tableau/PileTableau.java new file mode 100644 index 0000000..0d10226 --- /dev/null +++ b/DEV3.2/TP04/03_Tableau/PileTableau.java @@ -0,0 +1,35 @@ +public class PileTableau implements Pile { + + protected E[] elements; + + public PileTableau() { + this.elements = (E[]) new Object[16]; + } + + @Override + public void addFirst(E element) { + E[] nouveau = (E[]) new Object[16]; + nouveau[0] = element; + for (int i = 0; i != this.elements.length-1; i++) { + nouveau[i+1] = this.elements[i]; + } + this.elements = nouveau; + } + + @Override + public E removeFirst() { + E[] nouveau = (E[]) new Object[16]; + E temp = this.elements[0]; + for (int i = 1; i != this.elements.length; i++) { + nouveau[i-1] = this.elements[i]; + } + this.elements = nouveau; + return temp; + } + + @Override + public boolean isEmpty() { + return (this.elements[0] == null); + } + +} \ No newline at end of file