// Loop through every single element in array
for (int i = 0; i < amount; i++){
bool solved = true; // For now, we say that everything is sorted
for (int j = 0; j < amount - 1; j++){
if (data[j] > data[j + 1]){ // for descending order replace '>' with '<'
solved = false; // It turns out, everything isn't sorted
// swap elements
int tmp = data[j];
data[j] = data[j + 1];
data[j + 1] = tmp;
//----------------
}
}
if (solved) // If not a single element was greater than the element to it's right, everything can be considered sorted
break; // we end the algorithm, sorting is complete
}