how to create a bubble

is their a tutorial anywhere on how to create bubbles
What?
Do you mean bubble sort?
Last edited on
yes I am sorry should have added that
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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
}
Topic archived. No new replies allowed.