Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2. //////////// Exo1 /////////////////////
  3. public class Pair <K,V> {
  4. private final K key; //non modifiable
  5. private V value;
  6.  
  7. //constructeur
  8. public Pair(K k, V v){
  9. key = k;
  10. value = v;
  11. }
  12.  
  13. public K getKey() {
  14. return key;
  15. }
  16.  
  17. public V getValue() {
  18. return value;
  19. }
  20.  
  21. //Modifie la valeur
  22. public V setV(V v){ //ou void
  23. value =v;
  24. return v;
  25. }
  26.  
  27. //////////////////////////////////////////////
  28.  
  29. ////////// Exo2 //////////////////////
  30.  
  31. //Echange de 2 élément du tableau (pas générique)
  32. public static void swap(String [] Tab, int a, int b){
  33.  
  34. if(Tab== null || a<0 || b<0 || a>Tab.length || b>Tab.length) return; //sort
  35. else {
  36. String tmp;
  37. tmp = Tab[a];
  38. Tab[a] = Tab[b];
  39. Tab[b] = tmp;
  40. }
  41.  
  42. }
  43.  
  44. //Echange de 2 éléments du tableau (GENERIQUE)
  45. public static <T> void swap(T [] Tab, int a, int b){
  46.  
  47. if(Tab == null || a<0 || b<0 || a>Tab.length || b>Tab.length) return; //sort
  48. else {
  49. T tmp;
  50. tmp = Tab[a];
  51. Tab[a] = Tab[b];
  52. Tab[b] = tmp;
  53. }
  54.  
  55. }
  56.  
  57. ////////////////////////////////////////////////////
  58.  
  59. //////// Exo3 //////////////////////////////
  60.  
  61.  
  62. //////////////////////////////////////////////////
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement