C++
文章平均质量分 82
xufei96
SDET .net C#
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
第5章 树和二叉树(8)
例5-3 编写算法,求二叉树的深度 Python Codes: class TreeNode: def __init__(self,left=0,right=0,value=0): self.Left=left self.Right=right self.Value=value class Tree: def __init__(原创 2012-02-02 14:22:23 · 379 阅读 · 0 评论 -
第8章 查找(1)
8.2.2 有序表的折半查找 折半查找(Binary Search)又叫二分查找,其基本思想是:在有序表中,取中间的记录作为比较对象,如果要查找记录的关键码等于中间记录的关键码,则查找成功;若要查找记录的关键码小于中间记录的关键码,则在中间记录的左半区继续查找;若要查找记录的关键码大于中间记录的关键码,则在中间记录的右半区继续查找。不断重复上述查找过程,直到查找成功,或有序表中没有所要查找的记录原创 2012-02-07 15:28:26 · 400 阅读 · 0 评论 -
第7章 排序(6)
7.5 归并排序 归并排序主要是二路归并排序。二路归并排序的基本思想是:将两个有序表合并为一个有序表。 假设顺序表中n个记录为n个长度为1的有序表,从第1个有序表开始,把相邻的两个有序表两两合并成一个有序表,得到n/2个长度为2的有序表。如此重复,最后得到一个长度为n的有序表。 Python Codes: def __Merge(arr,start1,start2,end): wh原创 2012-02-07 14:49:16 · 425 阅读 · 0 评论 -
第7章 排序(5)
7.4 堆排序 C++ Codes: template void HeapSort(T vec[], int length) { for(int i=0;i<length;++i) { for(int j=length-1-i;j>0;--j) { if(vec[j]>vec[(j-1)/2]) { T val=vec[j]; vec[j]=vec[(j原创 2012-02-06 16:47:01 · 323 阅读 · 0 评论 -
第7章 排序(3)
7.2.3 简单选择排序 C++ Codes: template void SimpleSelectSort(T vec[],int length) { for(int i=0;i<length;++i) { int mark=i; for(int j=i;j<length;++j) { if(vec[j]<vec[mark]) mark=j; }原创 2012-02-06 14:26:56 · 323 阅读 · 0 评论 -
第7章 排序(1)
7.2简单排序方法 7.2.1 直接插入排序 C++ Codes: #pragma once #include "stdafx.h" template void DirectInsertSort(T vec[], int length) { for(int i=0;i<length-1;++i) { for(int k=0;k<=i;++k) { if(vec原创 2012-02-06 13:16:23 · 374 阅读 · 0 评论 -
第7章 排序(2)
7.2.2 冒泡排序 C++ Codes: template void BubbleSort(T vec[], int length) { for(int i=0;i<length;++i) { for(int j=0;j<length-i-1;++j) { if(vec[j]>vec[j+1]) { T val=vec[j+1]; vec[j+原创 2012-02-06 13:41:31 · 379 阅读 · 0 评论 -
第7章 排序(4)
7.3 快速排序 C++ Codes: template void QuickSort(T vec[],int low, int high) { int i=low; int j=high; int k=low; while(low<high) { while(k=vec[k]) --high; int val1=vec[k]; vec[k]=vec[high];原创 2012-02-06 16:04:38 · 355 阅读 · 0 评论 -
第5章 树和二叉树(10)
习题 5.10 编写算法,将二叉树中所有结点的左右子树相互交换。 C++ Codes: template class TreeNode { public: T Value; TreeNode *Left; TreeNode *Right; TreeNode(TreeNode *left=0,TreeNode *right=0,T value=0) { Value=value;原创 2012-02-02 16:56:09 · 372 阅读 · 0 评论 -
第5章 树和二叉树(7)
例5-2 统计出二叉树中叶子结点的数目 C++ Codes: template class TreeNode { public: T Value; TreeNode *Left; TreeNode *Right; TreeNode(TreeNode *left=0,TreeNode *right=0,T value=0) { Value=value; this->Left=l原创 2012-02-02 11:00:19 · 451 阅读 · 0 评论 -
第5章 树和二叉树(9)
习题 5.9 编写算法,求二叉树中分支结点的数目。 C++ Codes: template class TreeNode { public: T Value; TreeNode *Left; TreeNode *Right; TreeNode(TreeNode *left=0,TreeNode *right=0,T value=0) { Value=value; this->原创 2012-02-02 16:30:52 · 363 阅读 · 0 评论 -
C++怎样实现一个类的索引器
How to: Use Indexed Properties An indexed property typically exposes a data structure that is accessed using a subscript operator. A default indexed property allows the user to access the data转载 2012-01-12 10:09:03 · 1150 阅读 · 0 评论 -
第5章 树和二叉树(3)
2. 中序遍历(LDR) C++ Codes: template class Tree { public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void InOrder() { //Tree::InOrder2(this->Root); Tree::InOrder1(this->Root);原创 2012-02-01 11:03:47 · 467 阅读 · 1 评论 -
第5章 树和二叉树(4)
3. 后序遍历(LRD) C++ Codes: template class Tree { public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void LevelOrder() { Tree::LevelOrder2(this->Root); //Tree::LevelOrder1(thi原创 2012-02-01 14:30:19 · 386 阅读 · 0 评论 -
第5章 树和二叉树(5)
4. 层序遍历(Level Order) C++ Codes: template class Tree { public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void LevelOrder() { Tree::LevelOrder(this->Root); //Tree::LevelOrd原创 2012-02-01 15:43:23 · 469 阅读 · 0 评论 -
第5章 树和二叉树(2)
5.2.5 二叉树的遍历 1. 先序遍历。 C++ Codes: template class Tree { public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void PreOrder() { Tree::PreOrder2(this->Root); //Tree::PreOrder1原创 2012-01-31 16:04:41 · 388 阅读 · 0 评论 -
第5章 树和二叉树(1)
树形结构是一对多的非线性结构,非常类似于自然界中的树,数据元素之间既有分支关系,又有层次关系。 树形结构有树和二叉树两种,树的操作实现比较复杂,但树可以转换为二叉树进行处理。 二叉树的存储结构主要有三种:顺序存储结构、二叉链表存储结构和三叉链表存储结构。 采用顺序存储结构,是对非线性数据结构线性化,用线性结构来表示二叉树的结点之间的逻辑关系,所以需要增加空间。 二叉树的二叉链表存储结构可以原创 2012-01-31 15:13:03 · 445 阅读 · 0 评论 -
求0-2000内的所有质数(筛选法)
核心算法: 我们先设保存整数0~N的数组为sieve[N+1],设素数P(2若比素数P小的所有素数的倍数均已从sieve中删去,则比素数P大的非素数的所有因子均比P大。 Code: //Func.h #include "stdafx.h" #include using std::cout; using std::endl; void PrintNums(int num) {原创 2012-01-20 10:10:28 · 1033 阅读 · 1 评论 -
第3章 栈和队列(3)
3.2 队列 队列(Queue)是插入操作限定在表的尾部而其他操作限定在表的头部进行的线性表。队列又称为FIFO表或LILO表。 C++利用数组实现一个循环顺序队列: //Queue.h #pragma once #include "stdafx.h" #include using std::cout; namespace Andersoft{ template class CSeqQ原创 2012-01-19 15:39:39 · 373 阅读 · 0 评论 -
第2章 线性表(4)
C++实现一个单向链表: //Node.h #pragma once #include "stdafx.h" namespace Alexsoft { template class Node { public: T data; Node *next; Node(T val,Node *p){ data=val; next=p; } Node(T val原创 2012-01-17 15:45:01 · 457 阅读 · 0 评论 -
第3章 栈和队列(1)
栈的操作只能在表的一端进行,队列的插入操作在表的一端进行而其它操作在表的另一端进行,所以,把栈和队列称为操作受限的线性表。 3.1 栈 C++写一个利用数组实现栈的代码: //MyStack.h #pragma once #include "stdafx.h"; #include ; using std::cout; namespace Kingsoft { template cla原创 2012-01-18 16:36:16 · 348 阅读 · 0 评论 -
第2章 线性表(3)
C++实现一个顺序表 //Algri.h #include "stdafx.h" #include #include using std::cout; using std::vector; namespace Jeffery { template class SeqList { public: int Maxsize; private: vector data; int Las原创 2012-01-12 16:05:13 · 387 阅读 · 0 评论
分享