
再学数据结构
文章平均质量分 75
Json-zhang
求上进
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
顺序表
顺序表是利用数组来实现的线性结构,主要是能执行一些插入和删除的操作。 //A。h #ifndef A_H #define A_H //#include #include using namespace std; const int MaxListSize=20; template class SeqList { public: SeqList(T a[],int n=0); ~SeqLis原创 2013-07-18 18:26:30 · 479 阅读 · 0 评论 -
折半插入排序法
#include using namespace std; int main() { int i,j,t,low=0,high,mid; int a[10]={0,5,4,3,2,7,6,9,8,0}; for(i=1;i<10;i++) { t=a[i]; low=0; high=i-1; while(low<=high) { mid=原创 2013-08-29 09:09:48 · 555 阅读 · 0 评论 -
直接选择排序法
#include using namespace std; int main() { int i,j,min,t; int a[10]={1,2,5,4,3,7,6,9,8,0}; for(i=0;i<10;i++) { min=i; for(j=i;j<10;j++) { if(a[min]>a[j]) min=j; } t=原创 2013-08-29 09:27:52 · 542 阅读 · 0 评论 -
二叉链表的创建
#include #include using namespace std; struct BTNode { int data; BTNode * lchild,* rchild; }; const int MaxSize=100; class BinaryTree { public: BinaryTree(); ~BinaryTree(void); void原创 2013-08-16 09:59:54 · 1593 阅读 · 0 评论 -
基于邻接表的深度优先搜索
header.h #include using namespace std; const int MaxVertexNum=20; struct EdgeNode{ int adjvex; struct EdgeNode * next; }; struct VNode{ int data; EdgeNode * firstedge; }; class ALGraph原创 2013-08-26 13:23:56 · 974 阅读 · 0 评论 -
关于基于邻接矩阵的深度优先搜索
header.h#include #include using namespace std; const int MaxVertexNum=20; class MGraph { public: MGraph(); ~MGraph(); bool DFSTraverse(); int locateVex(int u); MGraph & InsertVex(int原创 2013-08-26 13:01:44 · 913 阅读 · 0 评论 -
用C++实现表达式求值
算法思想:使用两个栈,分别用来存储数和运算符,使用一个字符串来接受所要进行运算的表达式,用字符串中的符号与存储符号的栈进行比较,如果外来的运算符优先级大于栈内的运算符,则将存储数的栈顶出栈与字符串的下一个字符进行运算。否则将其压栈。最后得到的将是一个只需进行最后一步运算的两个栈,最后进行运算,直到存储符号的栈为空为止。下面的未涉及(),推广一下即可 #include #include #in原创 2013-08-14 10:57:48 · 1258 阅读 · 0 评论 -
邻接表的实现
邻接表的实现,主要是一个顶点的表,其节点结构为VNode,同时各个VNode作为头节点,来链接起它的邻接点,它的邻接点为EdgeNode。 header.h #include using namespace std; const int MaxVertexNum=20; struct EdgeNode{ int adjvex; struct EdgeNode * next; }原创 2013-08-25 17:33:18 · 1277 阅读 · 0 评论 -
邻接矩阵
对于图的一种表示方式,我觉得邻接矩阵是非常易于理解的一种结构,使用一个一维数组来存放各个顶点,用一个二维数组的下标来表示相应的顶点数组中的顶点,用二维数组的值来表示是否存在指向的关系。对于网,其值则可以表示相应的权值。 header.h #include #include using namespace std; const int MaxVertexNum=20; class MG原创 2013-08-24 14:05:56 · 774 阅读 · 0 评论 -
线索二叉树
header,h #include using namespace std; enum flag{Child,Thread}; struct TBNode{ char data; TBNode * lchild,* rchild; flag ltag,rtag; }; class ThreadBinaryTree{ public: ThreadBinaryTree()原创 2013-08-23 21:45:17 · 534 阅读 · 0 评论 -
稀疏矩阵
SparseMatrix.h #ifndef A_H #define A_H #include #include #include using namespace std; template struct Triple { int row,col; T value; }; const int MaxSize=100; template class SparseMatrix { public:原创 2013-07-23 15:37:28 · 673 阅读 · 0 评论 -
堆排序的实现
#include using namespace std; void sift(int a[],int start,int end) { int temp=a[start]; int parent=start; int child=2*start+1; while(child<end) { if(child<end&&a[child]<a[child+1]) child++;原创 2013-07-23 19:48:03 · 461 阅读 · 0 评论 -
VS编译器的记忆问题
#include #include //runtime_error在其中定义 using namespace std; int main(){ int ival; while(cin>> ival,!cin.eof()){ if (cin.bad()) throw runtime_err转载 2013-07-22 15:18:25 · 695 阅读 · 0 评论 -
行编辑问题的实现
这个问题主要是解决当用户发现刚刚键入一个是错误字符时,他可以补进一个"#",以表示前面一个字符无效;当发现错误较多时可以补进一个”@“,以表示当前行中的字符均无效。 #include #include #define maxSize 128 typedef struct SqStack{ char data[maxSize]; int top; }SqStack; void InitSta原创 2015-09-20 23:07:51 · 593 阅读 · 0 评论