Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=== Input User
- int ListSize = 10;
- int minRandom = 0;
- int maxRandom = 20;
- //=== Définition des variables
- IntList list;
- IntList MinEntries;
- IntList MaxEntries;
- int MinValue;
- int MaxValue;
- void setup() {
- noLoop();
- list = new IntList();
- MinEntries = new IntList();
- MaxEntries = new IntList();
- }
- void draw() {
- IntList list = FillListRandom(ListSize, minRandom, maxRandom);
- getIndex(list);
- print("Liste générée aléatoirement: ");
- println(list);
- println();
- print("La plus petite valeur de la liste est: ");
- println(MinValue(list));
- print("Cette valeur se situe en: ");
- println(MinEntries);
- println();
- print("La plus grande valeur de la liste est: ");
- println(MaxValue(list));
- print("Cette valeur se situe en: ");
- println(MaxEntries);
- }
- public int MinValue(IntList listp) {
- int MinV = listp.get(0);
- for (int i = 1; i <= listp.size()-1; i++) {
- if (listp.get(i) < MinV) { MinV = listp.get(i); }
- }
- return MinV;
- }
- public int MaxValue(IntList listp) {
- int MaxV = listp.get(0);
- for (int i = 1; i <= listp.size()-1; i++) {
- if (listp.get(i) > MaxV) { MaxV = listp.get(i); }
- }
- return MaxV;
- }
- public IntList FillListRandom (int sizelist, int minRandom, int MaxRandom) {
- IntList listp;
- listp = new IntList();
- for (int i = 0; i < sizelist; i++) {
- listp.append(int(random(minRandom, MaxRandom)));
- }
- return listp;
- }
- void getIndex (IntList list) {
- for (int i = 0; i <= list.size()-1; i++) {
- if (list.get(i) == MinValue(list)) {
- MinEntries.append(i);
- }
- if (list.get(i) == MaxValue(list)) {
- MaxEntries.append(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement