`
ding43930053
  • 浏览: 38979 次
社区版块
存档分类
最新评论

算法:利用泡沫算法,进行对int类型数组升序的排列

 
阅读更多




//泡沫算法,进行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;
	}}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics