![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构算法
Aff ''
你是我的文艺复兴
展开
-
【快排】查找数组第k小的数
void Search2(int *arr,int n){// int n = (sizeof(arr)/sizeof(arr[0])); if(arr == NULL && n < 2) { return ; } int min1 = arr[0] < arr[1] ? arr[0]:arr[1]; int min2 = arr[1] <...原创 2019-01-11 23:09:06 · 416 阅读 · 0 评论 -
【数据结构】二叉查找树(BST树)的构建、查找、插入、删除操作
二叉查找树又叫二叉排序树、二叉搜索树;二叉查找树其实是数据域有序的二叉树,即树上的每个节点都满足左子树上结点小于等于根节点,右子树上结点大于等于根节点数值; Ps:BST树中不能包含重复元素二叉树的操作包含建树、查询、删除、插入结点;构建BST树架构typedef int KeyType;typedef struct BstNode{ BstNode *leftch...原创 2019-06-26 18:22:23 · 499 阅读 · 0 评论 -
【LeetCode 144、94、145、102、107】二叉树的前序遍历、中序遍历、后序遍历、层次遍历 [递归、非递归]
LeetCode 144 前序遍历递归遍历:class Solution {public: vector<int> vec; vector<int> preorderTraversal(TreeNode* root) { if(root == NULL) { return vec;...原创 2019-05-24 20:28:35 · 283 阅读 · 0 评论 -
【LeetCode 236】C++实现递归、非递归求二叉树的最近公共节点
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */c...原创 2019-03-30 19:50:10 · 354 阅读 · 0 评论 -
【数据结构】线索二叉树
typedef char ElemType;#define END '#'typedef enum{LINK = 0,THREAD = 1} PointerTag;typedef struct BiThrNode{ BiThrNode *leftchild; BiThrNode *rightchild; PointerTag Ltag,Rtag; ElemType dat...原创 2019-03-18 23:59:10 · 187 阅读 · 0 评论 -
【数据结构】二叉搜索树
#include<windows.h>#include<assert.h>#include<limits.h>#include<iostream>#include<vector>#include<time.h>#include<stack>#include<queue>using ...原创 2019-03-20 00:49:39 · 141 阅读 · 0 评论 -
【数据结构】树的非递归遍历、层次遍历、第K层遍历规则
#include<windows.h>#include<assert.h>#include<limits.h>#include<iostream>#include<vector>#include<time.h>#include<stack>#include <queue>原创 2019-03-01 20:19:39 · 254 阅读 · 0 评论 -
【数据结构】树——前序中序推后序、中序后序推前序,二叉平衡树
#include<windows.h>#include<assert.h>#include<limits.h>#include<iostream>#include<vector>#include<time.h>using namespace std;#define END -1typedef int E...原创 2019-01-29 21:59:34 · 387 阅读 · 0 评论 -
【数据结构】单链表习题
头文件:“test.h” typedef int Elem_type;typedef struct Node{ Elem_type mdata; struct Node* pnext;}Node, *Link;void Init(Link phead);Node BuyNode(Elem_type val);//static Link BuyN...原创 2018-10-16 16:29:47 · 582 阅读 · 0 评论 -
【位运算】位运算判断奇偶数、位运算求和、位运算求平均数、位运算求二进制1的个数
位运算判断奇偶数: 2,4,6,8,10这样的数转化为二进制是10,100,1000,10000,将其减1后做与运算为0;x & (x-1) == 0 //偶数x & (x-1) != 0 //奇数位运算求平均数:int f(int x,int y){ return (x & y) + ((x ^ y) >> 1); }...原创 2019-06-27 22:58:33 · 902 阅读 · 0 评论