//// Exercise - arrays -- SORT entire (shrinking) array int a[]; int total; int biggest; float y; void setup() { // setup // size(600,600); a= new int[20]; reset(); } void draw() { // next frame // background(255); fill(0); textSize( 16 ); text( "The array size is: "+a.length, 20, 20 ); text( "Press 'r' key for random values in array.", width/2,20 ); text( "Press 'b' to move biggest to end", width/2,40 ); text( "Press 's' to sort entire array.", width/2,60 ); y= 70; for (int j=0; j biggest) biggest= a[j]; } } */ int whereBig( int a[], int m ) { //// Find INDEX OF biggest # in array a[m] int w=0; for (int j=0; j a[w]) w=j; } return w; } void swap( int[] a, int j, int k) { // swap two elements of array int tmp; tmp= a[j]; a[j]= a[k]; a[k]= tmp; } void bigToEnd( int a[], int m ) { // Move biggest to end int w; w= whereBig( a, m ); swap( a, w, m-1); } void sortAll( int a[], int many ) { // Sort the entire array. for ( int m=many; m>1; m=m-1 ) { bigToEnd( a, m ); } }