![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
排序
perlphp
代码是程序员的朋友,虽然没有热情,但是非常忠实。
展开
-
堆排序
#include #include using namespace std; void AdustDown(vector &arr,int curr,int len) { int child; while(curr * 2 + 1 <= len) { child = curr * 2 + 1; if (child + 1 <= len) { if (arr[child] < a原创 2017-07-13 09:33:44 · 174 阅读 · 0 评论 -
链表的二路归并排序
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* so转载 2017-07-13 11:18:12 · 1361 阅读 · 0 评论 -
单链表的快速排序
我们需要两个指针p和q,这两个指针均往next方向移动,移动的过程中保持p之前的key都小于选定的key,p和q之间的key都大于选定的key,那么当q走到末尾的时候便完成了一次支点的寻找。如下图所示: 既然两个指针都是从前往后遍历,那么链表值进行交换就简单了。找到支点后,支点左边和支点右边进行子问题递归,就回到快排原来的思路上去了。代码如下: struct Node {转载 2017-07-13 11:38:03 · 233 阅读 · 0 评论 -
无序数组中最小的k个数
对于一个无序数组,数组中元素为互不相同的整数,请返回其中最小的k个数,顺序与原数组中元素顺序一致。 给定一个整数数组A及它的大小n,同时给定k,请返回其中最小的k个数。 class KthNumbers { public: vector findKthNumbers(vector A, int n, int k) { // write code here原创 2017-07-24 17:25:01 · 576 阅读 · 0 评论