
数据结构
月已满西楼
某不知名学校毕业学生,某不知名名企软件工程师,擅长C++
python,Mysql
展开
-
斐波那契函数再总结--模板元编程
按照惯例先来一段代码: 先看feibo1#include<iostream>using namespace std;int feibo1(int n){ int res; int first = 1; int second = 1; if (n < 3) { return 1; } for(int i = 2; i <原创 2017-04-09 19:40:44 · 611 阅读 · 0 评论 -
二叉树中叶子节点的个数第K层的节点个数
叶子节点的个数size_t _GetLeefNode(Node *pRoot){ if (pRoot == NULL) return 0; if (NULL == pRoot->pLeft&&NULL == pRoot->pRight) return 1; return _GetLeefNode(pRoot->pLeft) + _GetLee原创 2017-07-29 22:13:16 · 1091 阅读 · 0 评论 -
day6-day9代码片段
1. 模拟实现atoi#include<iostream>#include<cassert>using namespace std;enum Legal{valid=0,legal=1};int flag = 1;int fuhao = 1;int strToInt(const char *str){ long long num = 0; while (*str !=原创 2017-07-07 23:10:32 · 599 阅读 · 0 评论 -
带有getMin栈
带有getMin栈#include<iostream>#include<stack>using namespace std;template<class T>class MinStack{public: void Pop() { if (st.top() == minSt.top()) { minSt.pop();原创 2017-07-21 13:52:53 · 248 阅读 · 0 评论 -
day19-day21代码片段
1. 1-n中某数字出现的次数#include<iostream>using namespace std;int getNum(int n,int k){ int count = 0; int x; for (int i = 1; x=n/i; i *= 10) { int high = x / 10; if (k == 0)原创 2017-07-21 23:32:09 · 418 阅读 · 0 评论 -
判断是否是栈的弹出序列&&二进制中1的个数
判断是否是栈的弹出序列bool IsPop(char *PopOrder, char *PushOrder,int len){ if (PopOrder == nullptr || PushOrder == nullptr || len <= 0) return false; bool Possible = false; char *PopStart = P原创 2017-07-23 00:14:08 · 311 阅读 · 0 评论 -
二叉树的层序遍历 N!结尾0的个数
二叉树的层序遍历void _LevelOrder(Node *pRoot) { Node *pCur = pRoot; queue<Node *> q; q.push(pCur); while (!q.empty()) { Node *pTop = q.front();原创 2017-07-24 00:09:44 · 311 阅读 · 0 评论 -
day16-day18代码片段
1. 二叉树的层序遍历void _LevelOrder(Node *pRoot) { Node *pCur = pRoot; queue<Node *> q; q.push(pCur); while (!q.empty()) { Node *pTop = q.front();原创 2017-07-17 14:18:27 · 274 阅读 · 0 评论 -
字符串或数组全排列的三种方法
先看最简单的一种:void perm2(int *arr, int n, int len){ for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { for (int k = 0; k < len; k++) {原创 2017-04-14 21:36:02 · 720 阅读 · 0 评论 -
STL常见面试题
红黑树的特性与其在C++ STL中的应用 map 、set、multiset、multimap的底层实现都是红黑树,epoll模型的底层数据结构也是红黑树,linux系统中CFS进程调度算法,也用到红黑树。 红黑树的特性: 根节点是黑色不能有两个连续的红节点空指针是黑色从任意一个结点出发,到后代中空指针的路径上,均包含相同数量的黑色结点。 http://blog.youkuaiyun.com/l原创 2017-09-02 17:03:52 · 4206 阅读 · 0 评论 -
使用两个栈实现一个队列+使用两个队列实现一个栈
1. 使用两个栈实现一个队列+使用两个队列实现一个栈两个栈实现一个队列#include<iostream>#include<stack>using namespace std;template<class T>class StackQueue{public: void Push(T data) { Spush.push(data); }原创 2017-07-20 13:18:01 · 286 阅读 · 0 评论 -
链式栈的实现
vs2013下编写的项目工程见 我的 github: https://github.com/excelentone/DataStructLinkStack.h#include "StackNode.h"template<typename T> class LinkStack{public: LinkStack() :_pTop(NULL) {} ~LinkStack()原创 2017-06-08 22:34:13 · 570 阅读 · 0 评论 -
含迭代器的红黑树
搜索二叉树含迭代器 vs2013下编写的项目工程见 我的 github: https://github.com/excelentone/DataStruct#include<iostream>using namespace std;#include<cassert>enum COLOR{ RED, BLACK };template<class K, class V>struct RBT原创 2017-06-08 21:34:57 · 685 阅读 · 0 评论 -
中缀表达式转后缀前缀表达式的简单方法
35,15,+,80,70,-,*,20,/ //后缀表达方式(((35+15)*(80-70))/20) //中缀表达方式 /,*,+,35,15,-,80,70, 20 //前缀表达方式 一个中缀式到其他式子的转换方法~~ 这里我给出一个中缀表达式~ a+b*c-(d+e) 第一步:按照运算符的优先级对所有原创 2017-04-02 00:34:59 · 1047 阅读 · 0 评论 -
两种方法位运算实现加法器
按照惯例先来一段代码: 先看feibo1#include<iostream>using namespace std;int feibo1(int n){ int res; int first = 1; int second = 1; if (n < 3) { return 1; } for(int i = 2; i <原创 2017-04-14 00:01:24 · 1382 阅读 · 0 评论 -
二叉树的创建和递归与非递归遍历
二叉树的创建//index要给引用!!! void _Create(Node *&pRoot,T *arr,T invalid,size_t sz,size_t &index) { if (arr[index] != invalid&&index < sz) { pRoot = new Node(arr[index]);原创 2017-05-18 09:56:16 · 618 阅读 · 2 评论 -
AVL树插入小结
一棵AVL树或者是空树,或者是具有以下性质的二叉搜索树: 1. 它的左右子树都是AVL树 2. 左子树和右子树高度之差(简称平衡因子)的绝对值不超过1(-1、0、1) 如果一棵二叉搜索树是高度平衡的,它就是AVL树。如果它有n个结点,其高度可保持在O(lgn),平均搜索时间复杂度O(lg(n)) 在二叉搜索树中,我们知道要插入一个元素,必须将他插到合适的位置,但是在AVL树原创 2017-05-22 10:19:55 · 906 阅读 · 0 评论 -
二叉树的面试题总结
二叉树的创建二叉树的高度二叉树某层节点的个数二叉树的镜像二叉树最远两个节点的距离二叉树的前中后层序递归非递归遍历判断二叉树是否是完全二叉树二叉树叶子节点的个数#include<iostream>#include<stack>#include<queue>using namespace std;template<class T>struct BinaryTreeNode{原创 2017-06-08 21:27:41 · 760 阅读 · 1 评论 -
搜索二叉树含迭代器
搜索二叉树含迭代器#include<iostream>#include<cassert>using namespace std;template<class K, class V>struct BSTNode{ BSTNode(const K& key=0, const V& value=0) : _pLeft(NULL) , _pRight(NULL) ,原创 2017-06-08 21:30:23 · 1050 阅读 · 0 评论 -
环形队列的实现
vs2013下编写的项目工程见 我的 github: https://github.com/excelentone/DataStruct CircleQueue.h#include<iostream>using namespace std;template<class T>class Queue{public: Queue(size_t size = 0) :_capacity(原创 2017-06-08 22:27:11 · 1135 阅读 · 0 评论 -
堆和优先级队列
搜索二叉树含迭代器 vs2013下编写的项目工程见 我的 github: https://github.com/excelentone/DataStructheap.h#include<iostream>#include<cassert>#include <vector>using namespace std;template<class T>struct Less{ boo原创 2017-06-08 21:37:26 · 360 阅读 · 0 评论 -
常见面试代码总结
排序归并排序#include<iostream>#include<cassert>using namespace std;void Merge(int *arr, int left,int mid, int right, int *temp){ int begin1 = left; int end1 = mid; int begin2 = mid + 1; i原创 2017-10-11 11:08:19 · 916 阅读 · 0 评论