摘要: 1)整体就是一个简单递归,左边排好序、右边排好序、让其整体有序 2)让其整体有序的过程里用了排外序方法 3)利用master公式来求解时间复杂度 4)归并排序的实质 时间复杂度O(N*logN),额外空间复杂度O(N) void Merge(int arr[], int left, int mid, 阅读全文
posted @ 2022-09-09 09:56 test369 阅读(13) 评论(0) 推荐(0) 编辑
摘要: int GetMax(int arr[], int left, int right) { if (left == right) return arr[right]; int mid = left + ((left-right)>>1); int leftMax = GetMax(arr, left, 阅读全文
posted @ 2022-09-08 17:20 test369 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 一个数组中有两种数出现了奇数次,其他数都出现了偶数次,怎么找到这两个数? int* a =new int[2]; int* GetOddTwo(int arr[], int size) { if (!arr) return NULL; int eor = 0; for (int i = 0; i < 阅读全文
posted @ 2022-09-08 11:08 test369 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 一个数组中有一种数出现了奇数次,其他数都出现了偶数次,怎么找到这一个数? int FindOddTimes(int arr[], int size) { if (!arr) return -1; int eor = 0; for (int i = 0; i < size; ++i) { eor ^= 阅读全文
posted @ 2022-09-08 11:05 test369 阅读(23) 评论(0) 推荐(0) 编辑
摘要: int BSLeft(int arr[], int size, int target) { if (!arr) return; int Left = 0; int Right = size-1; int Mid = 0; int Index = -1; while (Left < Right) { 阅读全文
posted @ 2022-09-08 11:05 test369 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 什么是局部最小值?如下: 给定一个序列,在这个序列中如果存在一个数,小于等于它的前一个数且小于等于它的后一个数,那么就称之为局部最小。 (注:如果是两边则只看一个即可,即如果是序列头部,则头部元素小于等于第二个元素即可;同理,如果是`尾部元素,则尾部元素小与次尾部元素即可) int GetPartM 阅读全文
posted @ 2022-09-08 11:05 test369 阅读(81) 评论(0) 推荐(0) 编辑
摘要: bool IsExistTarget(int arr[], int size, int target) { if (!arr) return false; int Left = 0; int Right = 0; int Mid = 0; while (Left < Right) { Mid = L 阅读全文
posted @ 2022-09-08 11:04 test369 阅读(25) 评论(0) 推荐(0) 编辑
摘要: //算法描述: //将待排序的序列中的元素依次插入已排序好的元素中 void InsertSort(int arr[], int size) { if (!arr || size < 2) return; for(int i = 1; i < size-1; ++i) { for (int j = 阅读全文
posted @ 2022-09-08 11:03 test369 阅读(11) 评论(0) 推荐(0) 编辑
摘要: //算法描述: //从前往后(从后往前)两两依次比较,若为逆序,则交换两元素,称为一趟冒泡 int BubbleSort(int arr[], int size) { if (!arr || size < 2) return; for(int i = 0; i < size-1; ++i) { fo 阅读全文
posted @ 2022-09-08 11:03 test369 阅读(15) 评论(0) 推荐(0) 编辑
摘要: //算法描述: //每次从待排序的元素中选择一个最小元素进行排序 void SelectSort(int arr[], int size) { if (!arr || size < 2) { return; } for (int i = 0; i < size-1; ++i) { int minIn 阅读全文
posted @ 2022-09-08 11:03 test369 阅读(7) 评论(0) 推荐(0) 编辑