
数据结构与算法
lpl312905509
这个作者很懒,什么都没留下…
展开
-
C语言实现堆结构及堆排序
//要想实现堆排序 首先需要实现一个大根(小根)堆#include <stdio.h>#include <stdlib.h>#include <vector>using namespace std;static vector<int> vec;static void myswap(int i,int j){ int temp = vec[i]; vec[i] = vec[j]; vec[j] = temp;}//将堆结构想象成原创 2021-06-13 16:49:47 · 214 阅读 · 0 评论 -
C语言实现快速排序
#include<stdlib.h>#include<iostream>#include<vector>#include <cstdlib>#include <ctime>using namespace std;static void myswap(vector<int>&,int,int);static void quickSort1(vector<int>& vec);static v原创 2021-06-12 17:36:59 · 199 阅读 · 0 评论 -
c语言实现归并排序递归版本与非递归版本
//归并排序//merge的过程可解决以下题目 //leetcode题 88题合并两个有序数组、//剑指offer 51题数组中的逆序对//小和问题#include<stdio.h>#include<stdlib.h>#include<iostream>#include<vector>#include <cstdlib>#include <ctime>using namespace std;static v原创 2021-06-07 13:47:12 · 166 阅读 · 0 评论 -
KMP算法原理及实现分析
KMP算法分析一、先来看看传统的暴力解法1.1 BF算法设计思想1、主串和模式串逐个字符进行比较2、当出现**「字符串不相同」时,也就是「失配」**时,主串的比较位置重置为起始位置的下一个字符位置,模式串的比较位置重置为起始位置1.2 BF算法的设计缺陷及解决方案在BF算法中,每次失配都需要回溯指向上次比较起始字符的下一个字符。通过观察发现:在回溯的时候,已匹配似乎**「有一部分」没必要继续比较了,这样可以降低算法的「时间复杂度」**2.1 KMP算法设计思路在匹配过程中出现字符比较不原创 2021-06-04 09:51:06 · 363 阅读 · 0 评论 -
设计一个有getMin功能的栈
/** 实现一个特殊的栈,在实现栈的基础功能的基础上,再实现返回栈中最小元素的操作** 1.pop push getMin 操作的时间复杂度都是O(1)* 2.设计的栈类型可以使用现成的栈结构 */public class Code05_GetMinStack { public static class MyStack1{ private Stack<Integer> stackData; private Stack<In原创 2020-09-06 08:34:17 · 171 阅读 · 0 评论 -
C实现各类排序算法代码
#include <iostream>using namespace std;//直接插入排序void insert_sort(int a[], int n){ int i, j, temp; for (i = 1; i < n; i++) { //暂存下标为i的数,下标从1开始,因为开始时 //下标为0的数,前面没有任何数,此时认为它是排好序的 ...原创 2020-01-28 11:18:29 · 190 阅读 · 0 评论 -
c++模板类快速排序
```cpp#include <assert.h>#include <iostream>using namespace std;template < typename T, int ONE_TIME_NUM = 16 >class Vector{public: Vector() { data_ptr_ = NULL; max_...原创 2020-01-10 10:22:41 · 357 阅读 · 0 评论 -
红黑树代码实现
请对照红黑树原剖析一起看,如要问题,请各位大神不吝赐教//网页测试工具 https://www.cs.usfca.edu/~galles/visualization/RedBlack.html#include <assert.h>#include <iostream>using namespace std;#define RED 1#define...原创 2020-01-07 22:13:59 · 256 阅读 · 0 评论 -
红黑树原理剖析
写到前面的话: 作者从毕业开始一直从事游戏开发,提供大量游戏实战模块代码及案例供大家学习与交流,希望以下知识可以带来一些帮助,如有任何疑问,请加群641792143交流与学习 或关注微信公众号 程序员干货区 闻道有先后,术业有专攻,希望大家不吝赐教首先介绍一下二叉树的几点性质:&nbs...原创 2019-12-26 23:09:26 · 411 阅读 · 1 评论 -
C/C++ 二叉树的递归与非递归遍历
#include <iostream>#include <string>#include <stack>#include <vector>using namespace std;struct Node{ int val; Node* left; Node* right; Node(int x):val(x),left(nullpt...原创 2019-10-18 14:31:50 · 354 阅读 · 0 评论 -
c语言之二分法查找循环版本与递归版本案例及代码
#include <stdio.h>#include <iostream>using namespace std;int binFind(int arr[], int value,int left,int right){ while (left <= right) { int mid = (left + right) >> 1; if...原创 2019-06-28 00:20:35 · 445 阅读 · 0 评论 -
c语言之快速排序代码及案例分析
#include <iostream>#include <stdio.h>void dis(int* arr, int n){ for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl;}void qsorts(int arr[]...原创 2019-06-27 21:08:38 · 247 阅读 · 0 评论