Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////// Exo1 /////////////////////
- public class Pair <K,V> {
- private final K key; //non modifiable
- private V value;
- //constructeur
- public Pair(K k, V v){
- key = k;
- value = v;
- }
- public K getKey() {
- return key;
- }
- public V getValue() {
- return value;
- }
- //Modifie la valeur
- public V setV(V v){ //ou void
- value =v;
- return v;
- }
- //////////////////////////////////////////////
- ////////// Exo2 //////////////////////
- //Echange de 2 élément du tableau (pas générique)
- public static void swap(String [] Tab, int a, int b){
- if(Tab== null || a<0 || b<0 || a>Tab.length || b>Tab.length) return; //sort
- else {
- String tmp;
- tmp = Tab[a];
- Tab[a] = Tab[b];
- Tab[b] = tmp;
- }
- }
- //Echange de 2 éléments du tableau (GENERIQUE)
- public static <T> void swap(T [] Tab, int a, int b){
- if(Tab == null || a<0 || b<0 || a>Tab.length || b>Tab.length) return; //sort
- else {
- T tmp;
- tmp = Tab[a];
- Tab[a] = Tab[b];
- Tab[b] = tmp;
- }
- }
- ////////////////////////////////////////////////////
- //////// Exo3 //////////////////////////////
- //////////////////////////////////////////////////
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement