/* find_smallest.pde Created by Justin Hsia, modified by Sam Wolfson Declares and uses a function that returns the index of the smallest float in an array. Implementation of an algorithm discussed from the Algorithms lecture. */ float[] numbers = {0.0, 3.14, -2.71, 120, 5}; // in Processing, program must be active in order to use functions void draw() { int index = findSmallest(numbers); println("Smallest: " + numbers[index] + " in index " + index); noLoop(); // don't run draw() again } // returns the index of the smallest number in an array int findSmallest(float[] list) { int smallest = 0; /* We implemented this in lecture */ int i = 0; while (i < list.length) { if (list[i] < list[smallest]) { smallest = i; } i = i + 1; } return smallest; }