
数据结构与算法
左耳朵猫
这个作者很懒,什么都没留下…
展开
-
二叉树的层次遍历
一句话总结:用队列,先进先出。原创 2017-10-26 23:51:00 · 260 阅读 · 0 评论 -
聊聊排列组合
假设有A、a、B、b、C、c六个元素,每个大小写元素不能相邻,求有多少种排列。第一个位置有6种可能(假设为A),第二个位置有4种(假设为B);第三个位置如果为a,那么只能2种排列,ABaCbc和ABacbC;第三个位置如果不为a(假设为C),有2种可能C和c,第四个位置有两种可能a和b(假设为a),第5个位置也有两种可能b和c,第6个位置只有一种可能。排列总数=6*4*2原创 2017-10-26 19:23:55 · 346 阅读 · 0 评论 -
二分查找的递归和非递归实现
#include int bfind(int a[], int val, int start, int end){ int mid = (start+end)/2; if (a[mid] > val) { return bfind(a, val, start, mid); } else if (a[mid] < val) { return bfind(a, val, mi原创 2017-11-04 14:32:38 · 257 阅读 · 0 评论 -
聊聊效率较高的几种常用排序算法
1、快速排序:主要思想是找个基准,将数据分成两半,不断迭代排序。注意所有元素都比基准大、或者都比基准小的情况。#include using namespace std;void quickSort(int *a, int left, int right){ if(left >= right)/*如果左边索引大于或者等于右边的索引就代表已经整理完成一个组了*/ {原创 2017-10-26 00:33:47 · 6103 阅读 · 0 评论 -
二叉树三种遍历的非递归算法
一句话总结:借用栈,注意后序遍历确认右子树遍历后才能遍历根。void preorderWithoutRecursion(BTNode* root){ if (NULL == root) { return; } BTNode* p = root; stack s; while (!s.empty() || p) { if (p) { cout data原创 2017-11-14 20:20:11 · 293 阅读 · 0 评论