摘要: Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the or 阅读全文
posted @ 2020-02-11 20:01 强威 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 桶排序是将待排序集合中处于同一个值域的元素存入同一个桶中,也就是根据元素值特性将集合拆分为多个区域,则拆分后形成的多个桶,从值域上看是处于有序状态的。对每个桶中元素进行排序,则所有桶中元素构成的集合是已排序的。 快速排序是将集合拆分为两个值域,这里称为两个桶,再分别对两个桶进行排序,最终完成排序。桶 阅读全文
posted @ 2020-02-11 15:24 强威 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 堆排序代码: #pragma once #include <vector> class HeapSort { public: void sort(std::vector<int>& seq) { // 构建大顶堆 for (int i = seq.size() / 2 - 1; i >= 0; -- 阅读全文
posted @ 2020-02-11 14:36 强威 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 快速排序 正如它的名字一样,是一种效率较高的排序方法,面试中也经常出现,正常情况下时间复杂度为 O(n * logn)。但是快排是一种不稳定排序算法,排序过程中会打乱元素顺序。 快排的核心是partition算法,partition算法步骤: 选取一个元素作为pivot。 将小于pivot的元素放在 阅读全文
posted @ 2020-02-11 14:35 强威 阅读(180) 评论(0) 推荐(0) 编辑