Advertisement
marwanpro

isn algo tri auto v2

Dec 9th, 2015
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. //=== Input User
  2. int ListSize = 10;
  3. int minRandom = 0;
  4. int maxRandom = 20;
  5.  
  6. //=== Définition des variables
  7. IntList list;
  8. IntList MinEntries;
  9. IntList MaxEntries;
  10. int MinValue;
  11. int MaxValue;
  12.  
  13.  
  14. void setup() {
  15.   noLoop();  
  16.   list = new IntList();
  17.   MinEntries = new IntList();
  18.   MaxEntries = new IntList();
  19. }
  20.  
  21.  
  22. void draw() {
  23.   IntList list = FillListRandom(ListSize, minRandom, maxRandom);
  24.   getIndex(list);
  25.   print("Liste générée aléatoirement: ");
  26.   println(list);
  27.   println();
  28.   print("La plus petite valeur de la liste est: ");
  29.   println(MinValue(list));
  30.   print("Cette valeur se situe en: ");
  31.   println(MinEntries);
  32.   println();
  33.   print("La plus grande valeur de la liste est: ");
  34.   println(MaxValue(list));
  35.   print("Cette valeur se situe en: ");
  36.   println(MaxEntries);
  37. }
  38.  
  39.  
  40. public int MinValue(IntList listp) {
  41.   int MinV = listp.get(0);
  42.   for (int i = 1; i <= listp.size()-1; i++) {
  43.     if (listp.get(i) < MinV) { MinV = listp.get(i); }
  44.   }
  45.   return MinV;
  46. }
  47.  
  48.  
  49. public int MaxValue(IntList listp) {
  50.   int MaxV = listp.get(0);
  51.   for (int i = 1; i <= listp.size()-1; i++) {
  52.     if (listp.get(i) > MaxV) { MaxV = listp.get(i); }
  53.   }
  54.   return MaxV;
  55. }
  56.  
  57.  
  58. public IntList FillListRandom (int sizelist, int minRandom, int MaxRandom) {
  59.   IntList listp;
  60.   listp = new IntList();
  61.   for (int i = 0; i < sizelist; i++) {
  62.     listp.append(int(random(minRandom, MaxRandom)));
  63.   }
  64.   return listp;
  65. }
  66.  
  67.  
  68. void getIndex (IntList list) {
  69.   for (int i = 0; i <= list.size()-1; i++) {
  70.     if (list.get(i) == MinValue(list)) {
  71.       MinEntries.append(i);
  72.     }
  73.     if (list.get(i) == MaxValue(list)) {
  74.       MaxEntries.append(i);
  75.     }
  76.   }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement