#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void bubleSort(double array[],int len){
double temp = 0.0;
for(int i = 0; i < len-1; i++){
for(int j = 0; j < len-1-i; j++){
if(array[j] > array[j+1]){
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}
void display(double arr[],int len){
for(int i = 0; i < len; i++){
cout<<arr[i]<<"\t";
}
}
int main() {
int len = 10;
double arrayTest[len] = {-2,15,65,2,34,87,99,45,66,20};
bubleSort(arrayTest,len);
display(arrayTest,len);
return 0;
}
复试3.1冒泡排序c++
最新推荐文章于 2021-04-01 12:00:22 发布
本文详细介绍了冒泡排序算法的实现过程,通过C++代码展示了如何对一个双精度浮点数数组进行排序,并提供了完整的代码示例。文章首先定义了一个冒泡排序函数,该函数接收一个数组和数组长度作为参数,然后使用双重循环来比较并交换数组中的元素,最终实现数组的升序排列。此外,还提供了一个显示排序后数组的函数。
406

被折叠的 条评论
为什么被折叠?



