This is yet another bubble sort.
Bubble Sort
int main(){
int arr[] = {8, 3, 5, 1, 2, 9, 0, 2, 4, 6};
bubble_sort(arr, 10);
for (register int i = 0; i < 10; i++)
std::cout << arr[i] << std::endl;
}
void bubble_sort(int *array, int len) {
bool done;
int* array_begin = array;
int* array_end = array_begin;
for (register int i = 0; i < len; i++) array_end++;
while (!done) {
done = true;
for (register int* i = array_begin; i != array_end; i++) {
int* j = i;
j++;
if (*i > *j) {
int temp = *i;
*i = *j;
*j = temp;
done = false;
}
}
}
}
seanbp 4 Junior Poster
arkoenig 340 Practically a Master Poster
seanbp 4 Junior Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
mrnutty 761 Senior Poster
seanbp 4 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.