
c++ 数据结构
文章平均质量分 58
沐沐余风
啦啦啦啦啦~
展开
-
data structure --Queue(基于数组的实现)
#includeusing namespace std;const int maxqueue=10;template class ArrayQueue{public: ArrayQueue(); bool empty() const; bool full() const; int size() const; void append(T &item); void serve原创 2014-01-04 17:27:33 · 975 阅读 · 0 评论 -
排序算法总结
借用一张图,直观对比各种排序算法的性能 1.快速排序要点:每次选择一个**基准元素**pivot,将小于pivot的移到左边,大于pivot的移到右边。 这个动图很赞 这里写链接内容int mypartition(int* array, int left, int right) { int pivot = array[left]; int low = left, high =原创 2017-09-21 16:41:03 · 250 阅读 · 0 评论 -
二分查找
在一个有序的数组中,用二分查找来寻找目标元素。时间复杂度O(logn)1、普通版二分查找不考虑重复元素的情况int binarySearch(vector<int>& data, int target) { int left = 0, right = data.size() - 1;//注意“-1” while (left <= right) {//注意“<=” in原创 2017-09-12 17:58:18 · 260 阅读 · 0 评论 -
STL 最大堆、最小堆的应用
1.priority_queuepriority_queue默认是最大堆,要用最小堆的话改变一下比较函数priority_queueint, vectorint>, lessint>> maxHeap;priority_queueint, vectorint>, greaterint>> minHeap;也可以自定义比较函数struct cmp{ bool o原创 2017-09-16 22:45:51 · 14973 阅读 · 0 评论 -
c++ split字符串拆分
c++ stl没有字符串拆分函数,这里参考网上的博客写了一个,备忘。vector<string> splitString(const string& s, const string& c) { vector<string> v; int start = 0; int end = s.find(c); while (string::npos != end) {原创 2017-09-08 13:13:52 · 714 阅读 · 0 评论 -
面试题-面向对象篇
面向对象问题汇总类的大小Q:一个只含有虚函数的类的size为多少? A:参考这个博客 #类中的元素 0. 成员变量 1. 成员函数 2. 静态成员变量 3. 静态成员函数 4. 虚函数 5. 纯虚函数 #影响对象大小的因素 0. 成员变量 1. 虚函数表指针(_vftptr) 2. 虚基类表指针(_vbtptr)原创 2017-09-22 18:45:19 · 712 阅读 · 0 评论 -
数据结构-二叉树的前序、中序、后序遍历的递归和非递归实现
在leetcode刷题,很多地方会考察到二叉树的遍历。 深度优先遍历DFS和广度优先遍历BFS看这里【链接】 这篇总结一下前序、中序、后序遍历的实现,备忘。1.基础知识二叉树的定义如下:struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(原创 2017-05-25 01:18:02 · 875 阅读 · 0 评论 -
数据结构-二叉树的深度优先和广度优先遍历
1.基本概念DFS深度优先遍历:沿着树的深度遍历树的节点,先访问根结点,然后是左子树,右子树 BFS广度优先遍历:横向遍历,沿着树的宽度,先访问根结点,然后左右子节点。然后是上述左右子节点的子节点,一层一层往下。 以下图为例: DFS的结果为【ABDECFG】 BFS的结果为【ABCDEFG】2.递归实现void DFS(TreeNode* root, vector<int>& ans)原创 2017-05-25 11:47:34 · 1163 阅读 · 0 评论 -
data structure--Stack(基于数组实现)
#includeusing namespace std;const int maxstack=10;template class ArrayStack{public:ArrayStack();T& top();void pop();void push(T&);bool IsEmpty() const;bool full() const;void clear();int原创 2014-01-04 17:31:46 · 733 阅读 · 0 评论 -
面向对象:封装、继承、多态
概念太多,总结一下,备忘。1.三大特性封装 隐藏对象的属性和实现细节,仅对外提供公共访问方式。继承 代码重用,子类继承父类的函数构造函数的覆盖: (1)父类没有构造函数或只有无参构造函数。 子类无需显示调用父类的构造函数,系统自动在调用子类构造函数前调用父类的构造函数。 (2)父类只有有参构造函数 子类必须显示调用父类构造函数 (3)父类有无参和有参的构造函数 子类不显示调用原创 2017-09-14 22:44:18 · 366 阅读 · 0 评论