
数据结构
xiaxzhou
这个作者很懒,什么都没留下…
展开
-
【数据结构】 堆
堆排序与快速排序,归并排序一样都是时间复杂度为O(N*logN)void MakeHeap(int * array, int len){ for (auto i = len - 1; i >= 1;--i) { if (array[(i-1)/2] < array[i]) { std::swap(array[i / 2], a原创 2017-06-02 18:01:30 · 295 阅读 · 0 评论 -
【数据结构】搜索二叉树
手写实现搜索二叉树:树的节点定义:class TreeNode{public: TreeNode(int v) :value(v){}; TreeNode* left_son = NULL; TreeNode* right_son = NULL; TreeNode* p = NULL; //一定保存双亲的指针 int value = 0;原创 2017-08-25 17:09:00 · 380 阅读 · 0 评论 -
【语法】sizeof和strlen
http://blog.youkuaiyun.com/niushuai666/article/details/7677210一、sizeofsizeof(…)是运算符,而不是一个函数。其值在编译时即计算好了。 由于在编译时计算,因此sizeof不能用来返回动态分配的内存空间的大小。具体而言,当参数分别如下时,sizeof返回的值表示的含义如下: 数组——编译时分配的数组空间大小; 指针——原创 2017-08-31 10:50:18 · 138 阅读 · 0 评论 -
【算法题】对称二叉树判断
解法1:分层遍历二叉树,判断每一层的节点是否轴对称。#include <iostream>#include <vector>#include <algorithm>#include <numeric>using namespace std;#define debug_struct TreeNode { int val; struct TreeNode *left;原创 2017-09-02 18:50:08 · 389 阅读 · 0 评论 -
【剑指offer】题61:之字打印二叉树
vector<vector<int>> Print(TreeNode* pRoot){ vector<vector<int>> vec; if (pRoot== NULL) return vec; stack<TreeNode*> my_stack[2]; int cur_deep(0); int next_deep(1); my_stac原创 2017-09-02 22:00:54 · 263 阅读 · 0 评论 -
【剑指offer】题61:二叉树序列化、反序列化
#include <iostream>#include <string>#include <sstream>using namespace std;struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x),原创 2017-09-03 10:32:58 · 279 阅读 · 0 评论