Advertisement

bubble, selection, insertion, merge, quick, shell, heap, counting, bucket, radix sorts 的 C++ 实现

阅读量:

文章结构概览

  • 时间复杂度为O(n²)的算法
      • 冒泡排序
      • 选择排序
      • 插入排序
    • 时间复杂度为O(nlogn)的算法

      • 归并排序
      • 快速排序
      • 希尔排序
      • 堆排序
    • 其他类型的算法

      • 计数排序Ο (n+k)
      • 桶排序 O(n+c)
      • 基数排序 O(n*k)
    • 排序性能对比表格

    • 相关链接

O( n*n )算法

冒泡排序

算法思路
通过逐一进行配对比较,将数值较小的元素向前移动,首次比较的索引区间设定为0至(N-1),而最终一轮比较所涉及的范围则限定在0至1之间。
算法实现
从本次执行结果可以看出,当对十万条数据进行排序操作时,所耗费的时间为674毫秒。

复制代码
    //冒泡排序 
    #include<iostream>  
    #include<time.h>
    #include <iomanip>
    #include<stdlib.h> 
    using namespace std;
    const int N = 10000;
    int a[N+5];
    int main(){ 	
    	srand(time(NULL));

全部评论 (0)

还没有任何评论哟~