随笔分类 -  数据结构与算法

摘要:#include #include #include #include using namespace std; const int N = 1e5 + 10, M = 1e6 + 10; char buffs[N], buffp[N], p[N], s[M]; int n, m; int ne[N 阅读全文
posted @ 2021-07-15 19:07 青衫客36 阅读(92) 评论(0) 推荐(0) 编辑
摘要:// 最大堆的操作 // 最大堆的创建 typedef struct HeapStruct *MaxHeap; struct HeapStruct { ElementType *Elements; // 存储堆元素的数组 int Size; // 堆的当前元素个数 int Capacity; // 堆的最大容量 }; MaxHeap Create(int MaxSize) { /... 阅读全文
posted @ 2019-09-16 21:20 青衫客36 阅读(129) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <cstdio> #include <cstdlib> using namespace std; // 判断是否同一棵二叉搜索树 /* 求解思路: 1. 搜索树表示 2. 建搜索树T 3. 判别一序列是否与搜索树一致 */ // 搜索树表示 typedef struct TreeNode *Tree; struct TreeNode { i 阅读全文
posted @ 2019-09-16 21:20 青衫客36 阅读(177) 评论(0) 推荐(0) 编辑
摘要:// 二叉搜索树的查找操作Find Position Find(ElementType X, BinTree BST) { if(!BST) return NULL; if(X > BST->Data) return Find(X, BST->Right); else if(X < BST->Data) return Find(X, BST->Left); else return BST; } / 阅读全文
posted @ 2019-09-05 10:35 青衫客36 阅读(152) 评论(0) 推荐(0) 编辑
摘要:// 树的同构 /* 1. 二叉树的表示 2. 建二叉树 3. 同构判别 */ // 1. 二叉树的表示 // 结构数组表示二叉树: 静态链表 #define MaxTree 10 #define ElementType char #define Tree int #define Null -1 struct TreeNode { ElementType Element; Tree Left; T 阅读全文
posted @ 2019-09-04 17:55 青衫客36 阅读(162) 评论(0) 推荐(0) 编辑
摘要:// 遍历二叉树的应用 // 输出二叉树中的叶子结点 // 在二叉树的遍历算法中增加检测结点的"左右子树是否都为空" void PreOrderPrintLeaves(BinTree BT) { if(BT) { if(!BT->Left && !BT->Right) printf("%d", BT->Data); PreOrderPrintLeaves(BT->Left); PreOrderPr 阅读全文
posted @ 2019-09-04 17:54 青衫客36 阅读(183) 评论(0) 推荐(0) 编辑
摘要:// 二叉树的存储结构 typedef struct TreeNode *BinTree; typedef BinTree Position; struct TreeNode { ElementType Data; BinTree Left; BinTree Right; }; void PreOrderTraversal(BinTree BT) { if(BT) { printf("%d", B 阅读全文
posted @ 2019-09-04 17:53 青衫客36 阅读(192) 评论(0) 推荐(0) 编辑
摘要:#include <cstdio> typedef struct LNode *List; struct LNode { ElementType Element[MAXSIZE]; int length; }; // 顺序查找 int SequentialSearch(List Tb1, ElementType K) { int i; Tb1->Element[0] = K; for(i = Tb 阅读全文
posted @ 2019-09-04 17:52 青衫客36 阅读(109) 评论(0) 推荐(0) 编辑
摘要:#include <cstdio> #include <cstdlib> // 多项式相乘 相加 // 数据结构设计 typedef struct PolyNode *Polynomial; struct PolyNode { int coef; int expon; Polynomial link; }; Polynomial ReadPoly(); void Attach(int c, int 阅读全文
posted @ 2019-09-02 19:07 青衫客36 阅读(1756) 评论(0) 推荐(1) 编辑
摘要:1. 循环队列 2. 链式队列 阅读全文
posted @ 2019-09-01 10:41 青衫客36 阅读(129) 评论(0) 推荐(0) 编辑
摘要:1. 顺序存储 共享栈 3. 链式栈 阅读全文
posted @ 2019-09-01 10:38 青衫客36 阅读(219) 评论(0) 推荐(0) 编辑
摘要:1. 顺序表 2. 链表 阅读全文
posted @ 2019-08-29 15:16 青衫客36 阅读(163) 评论(0) 推荐(0) 编辑
摘要:// 求最大子列和 #include <cstdio> int a[5]; // O(n^3) int MaxSeq1(int a[], int n) { int max = 0, sum = 0; for(int i = 0; i < n; ++ i) { for(int j = i; j < n; ++ j) { sum = 0; for(int k = i; k <= j; ++ k) { 阅读全文
posted @ 2019-08-27 19:20 青衫客36 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2019-08-27 17:49 青衫客36 阅读(91) 评论(0) 推荐(0) 编辑
摘要:/* 计时程序 */ #include #include clock_t start, stop; /* clock_t 是clock()函数返回的变量类型 */ double duration; /* 记录被测函数运行时间, 以秒为单位 */ int main() { /* 不在测试范围内的准备工作写在clock()调用之前 */ start = clock(); // 开始计时... 阅读全文
posted @ 2019-08-27 17:30 青衫客36 阅读(165) 评论(0) 推荐(0) 编辑
摘要:例二: 多项式 运行时间不到一个tick, 那怎么才能显示出一个tick所用的时间呢?(即如何测出不到1个tick的程序运行时间?) 让被测函数重复运行多次, 使得测出的总的时钟打点数间隔充分长, 最后计算出被测函数平均每次运行的时间即可 阅读全文
posted @ 2019-08-27 17:27 青衫客36 阅读(335) 评论(0) 推荐(0) 编辑
摘要:考试报名系统是对考试报名管理的简单模拟,用菜单选择方式完成下列功能:输入考生信息;输出考生信息;查询考生信息;添加考生信息;修改考生信息;删除考生信息。每条考生信息由准考证号、姓名、性别、年龄、报考类别等信息组成。 要求:定义一个专用的类型 ElemType,用于描述考生信息,数据结构用一个类描述, 阅读全文
posted @ 2019-07-31 18:40 青衫客36 阅读(258) 评论(0) 推荐(0) 编辑
摘要:小明初学C++,已明白了四则运算、关系运算、逻辑运算、赋值运算、输入输出、简单选择和循环结构的用法,但他的英语不太好,记不住太多的保留字,于是他利用汉语拼音做保留字,山寨C++,发明了一种表达自己思想的算法描述规则。 规则很简单:他将开始程序头部以一个拼音名字标记,C++程序中的"{,}"用拼音“k 阅读全文
posted @ 2019-07-31 18:35 青衫客36 阅读(282) 评论(0) 推荐(0) 编辑
摘要:族谱(或称家谱)是一种以表谱形式,记载一个以血缘关系为主体的家族世系繁衍和重要人物事迹的特殊图书体裁。族谱是中国特有的文化遗产,是中华民族的三大文献(国史,地志,族谱)之一,属珍贵的人文资料,对于历史学、民俗学、人口学、社会学和经济学的深入研究,均有其不可替代的独特功能。本题对族谱管理进行简单的模拟 阅读全文
posted @ 2019-07-31 18:33 青衫客36 阅读(683) 评论(0) 推荐(1) 编辑
摘要:#include #include #include using namespace std; #define MAXE 20 // 线性表中最多的元素个数 #define MAXR 10 // 基数的最大取值 #define MAXD 8 // 关键字位数的最大取值 // 排序数据节点类型 typedef struct node { char data[MAXD]; struc... 阅读全文
posted @ 2019-05-29 11:25 青衫客36 阅读(146) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示