算法导论22习题解答(冒泡算法)

CLRS 2-2 :冒泡排序算法的正确性

解答:

这里我只实现了冒泡算法,证明什么的,我也不大会.

#include <iostream>
using namespace std;

//冒泡排序
#define LEN 35
int main()
{
int* a =new int[LEN];
for(int i =0; i < LEN; i++)
a[i]
= i -5;

for(int i =0; i < LEN; i++)
for(int j = LEN -1; j > i; j--)
{
if(a[j] > a[j-1])
{
int temp = a[j];
a[j]
= a[j-1];
a[j
-1] = temp;
}
}

for(int i =0; i < LEN; i++)
cout
<<a[i]<<endl;
return 0;
}
---
可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
原文地址:https://www.cnblogs.com/null00/p/2065084.html