/*
*
*/
//================================================================================
bool loopFLAG = true;
byte arrayLength = 8;
byte theArray[8] = {55, 42, 69, 36, 13, 99, 87, 79};
//================================================================================
void setup() {
Serial.begin(9600);
Serial.print("Setup is now... ");
Serial.println("complete!");
} // setup
//================================================================================
void loop() {
if (loopFLAG == true) {
// PRINT OUT THE ORIGINAL ARRAY
Serial.println();
Serial.println("the original:");
for (int i = 0; i < arrayLength; i++) {
Serial.print(theArray[i]);
Serial.print(" ");
}
Serial.println();
// PUT ARRAY IN ORDER, RISING
for (int j = (arrayLength - 1); j > 0; j--) {
for (int i = (arrayLength - 1); i > 0; i--) {
if (theArray[i] < theArray[i - 1]) {
byte tempSpot = theArray[i - 1];
theArray[i - 1] = theArray[i];
theArray[i] = tempSpot;
}
} // compare element to other elements
} // run the for loop as many times as there are elements
// PRINT OUT THE ORDERED ARRAY, ASCENDING
Serial.println();
Serial.println("ascending:");
for (int i = 0; i < arrayLength; i++) {
Serial.print(theArray[i]);
Serial.print(" ");
}
Serial.println();
// PRINT OUT THE ORDERED ARRAY, DESCENDING
Serial.println();
Serial.println("descending:");
for (int i = (arrayLength - 1); i >= 0; i--) {
Serial.print(theArray[i]);
Serial.print(" ");
}
Serial.println();
// PRINT OUT THE ORDERED ARRAY, UP/DOWN
Serial.println();
Serial.println("up/down:");
for (int i = 0; i < arrayLength; i++) {
if (i < (arrayLength - 1)) {
i++;
}
Serial.print(theArray[i]);
Serial.print(" ");
Serial.print(theArray[i - 1]);
Serial.print(" ");
}
Serial.println();
// PRINT OUT THE ORDERED ARRAY, DOWN/UP
Serial.println();
Serial.println("down/up:");
for (int i = (arrayLength - 1); i >= 0; i--) {
if (i > 0) {
Serial.print(theArray[i - 1]);
Serial.print(" ");
}
Serial.print(theArray[i]);
Serial.print(" ");
i = i - 1;
}
Serial.println();
// PRINT OUT THE ORDERED ARRAY, RANDOMLY
Serial.println();
Serial.println("rando!");
loopFLAG = false;
Serial.println();
Serial.println("The loop has stopped!");
} // loop tag
} // loop
//================================================================================