随笔分类 - Data Structure
tons of ADT: List, stack, queue, binary tree, graphic
algorithms: search && sort
关注典型数据结构以及与他们相联系的算法
摘要:第一章:1、学习笔记http://www.ezikao.com.cn/bbs_disp.asp?Boardid=37&ID=159472、有关时间复杂性的讨论 http://www.ezikao.com.cn/bbs_disp.asp?Boardid=37&ID=161013、考题http://www.ezikao.com.cn/bbs_disp.asp?Boardid=37&ID=16001第二...
阅读全文
摘要:这里涉及到二叉树的非递归操作有:先序遍历、中序遍历、后序遍历 ====数据结构==== 树结点: struct Node { char data; Node * left; Node * right; }; 标志: enum Tag{goLeft, goRight, goBack }; goLeft指示访问左子树 goLeft指示访问右子树(左子树已访问) goBac...
阅读全文
摘要:google面试题: #include #include #include using namespace std; struct Node { char data; Node * left; Node * right; }; enum Tag{goLeft, goRight, goBack }; /* 打印从根到叶子结点之路径 */ void PrintP...
阅读全文
摘要:今天做yahoo的在线笔试碰到这个题,当时没想起来 设n0, n1, n2为度为0, 1, 2的节点 对任意二叉树有 n0 = n2 + 1 .........(1) 对于完全二叉树而言,叶子节点只出现在最后2层. 即每个节点左右子数的高度最多相差1 可以很容易知道,完全二叉树中度为1的节点为0个或1个(即至多1个) 由n0+n1+n2=total, 且有(1)式得, 2*n0...
阅读全文
摘要:参考《Introduce to Algorithm》 1 #ifndef MAX_HEAP_H 2 #define MAX_HEAP_H 3 4 const int MAX_SIZE = 100 + 1; 5 6 template 7 class MaxHeap 8 { 9 public: 10 MaxHeap(); 11 MaxH...
阅读全文
摘要:1 #ifndef MINHEAP_H 2 #define MINHEAP_H 3 4 const int MAX_HEAP_SIZE = 100; 5 6 template class MinHeap 7 { 8 public: 9 MinHeap(); 10 MinHeap(Type arr[], int size); 11 ...
阅读全文
摘要:#ifndef SORT_H#define SORT_H//选择排序:直接选择排序、竞标赛排序template void selectSort(Type arr[], int size){ int i, j; int index; for(i = 0; i void simpleInsertSort(Type arr[], int size){ int i, j; ...
阅读全文
摘要:HString.h 1 #ifndef HSTRING_H 2 #define HSTRING_H 3 4 #include 5 using namespace std; 6 7 const int MAX_SIZE = 128; 8 9 class HString10 {11 public:12 HString();13 HString(const HString &s...
阅读全文
摘要:BinaryTree.h 1 #ifndef BINARYTREE_H 2 #define BINARYTREE_H 3 4 #include 5 using namespace std; 6 7 const int MAX_NODES_SIZE = 100; 8 9 template class BinaryTree; 10 11 template class ...
阅读全文
摘要:GenList.hCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 #ifndef GENLIST_H 2 #define GENLIST_H 3 4 #include 5 6 #define HEAD 0 7 #define ...
阅读全文
摘要:Fibonacci函数定义: n = 0, fib(n) = 0; n = 1, fib(n) = 1; 其他, fib(n) = fib(n-1)+fib(n-2)
Ackerman函数定义: m = 0, ack(m, n) = n+1; n = 0, ack(m, n) = ack(m-1, n); 其他, ack(m, n) = ack(m-1, ack(m, n-1))
阅读全文
摘要:这是实验心理学的一个经典问题,心理学家把一只老鼠赶进迷宫,在唯一出口放置奶酪,要求能找到一条最佳路径到达出口。这里使用递归求解
阅读全文
摘要:Hanoi塔问题,这是一个古典的数学问题,是一个只有用递归方法解决的问题。问题是这样的:古代有一个梵塔,塔内有3个座A,B,C,开始时A座上有64个盘子,盘子大小不等,大的在下,小的在上。有一个老和尚想把这64个盘子从A座移到C座,但每次只允许移动一个盘,且在移动过程中在3个座上都始终保持大盘在上,小盘在下。在移动过程中可以利用B座。
将n个盘子从A座移到C座可以分解为以下3个步骤:
(1).将A上n-1个盘借助C座先移到B座上;
(2).把A座上剩下的一个盘移到C座上;
(3).将B上n-1个盘借助A座先移到C座上。
阅读全文
摘要:计算表达式,这里实现了后缀表达式计算,运算符operand包括: + - * / ^, 操作数operator为double类型。以后再加上中缀表达式变为后缀表达式的函数...
阅读全文
摘要:LinkList.h 1 #ifndef LINKLIST_H 2 #define LINKLIST_H 3 4 5 6 template class Node 7 { 8 //friend class LinkList; 9 public:10 Node();11 Node(const Type &item);12 ~No...
阅读全文
摘要:SqList.h 1 #ifndef SQLIST_H 2 #define SQLIST_H 3 4 //#include 5 6 #define LIST_INIT 100 7 #define LIST_INCREMENT 100 8 9 template class SqList10 {11 public:12 SqList();13 ~SqList();14 ...
阅读全文