//泡沫算法,进行int类型数组的排列:一 #include <stdafx.h> #include <iostream> #include <stdlib.h> using namespace std; #define length 6 void main() { double d[length]={87.5,60.8,20.1,96.2,11.6,77.8}; double temp; for (int i=0;i<length;i++) { for (int j=0;j<length-i-1;j++) { if (d[j]>d[j+1]) { temp = d[j+1]; d[j+1]=d[j]; d[j] = temp; } } } for (int j=0;j<length;j++) { cout <<d[j]<<endl; }}//泡沫算法,进行int类型数组的排列:二(动态检测数组的长度) #include <stdafx.h> #include <iostream> #include <stdlib.h> //动态检测数组的长度using namespace std; void main(){ int length = sizeof(a)/sizeof(*a);using namespace std; double d[length]={87.5,60.8,20.1,96.2,11.6,77.8}; double temp; for (int i=0;i<length;i++) { for (int j=0;j<length-i-1;j++) { if (d[j]>d[j+1]) { temp = d[j+1]; d[j+1]=d[j]; d[j] = temp; } } } for (int j=0;j<length;j++) { cout <<d[j]<<endl; }}