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

摘要:通过链表实现栈 #include<iostream> #include "chainList.cpp" using namespace std; template<class T> class linkedStack { public: explicit linkedStack(int initia 阅读全文
posted @ 2022-06-11 21:48 里列昂遗失的记事本 阅读(25) 评论(0) 推荐(1)
摘要:构建数组栈类 代码 #include <iostream> using namespace std; // 改变一个一维数组的长度 template<class T> void changeLength1D(T *&a, int oldLength, int newLength) { if (new 阅读全文
posted @ 2022-06-05 21:47 里列昂遗失的记事本 阅读(25) 评论(0) 推荐(0)
摘要:对角矩阵类(部分方法C++) 代码 #include<iostream> using namespace std; template<class T> class diagonalMatrix { public: explicit diagonalMatrix(int theN = 10); ~di 阅读全文
posted @ 2022-06-05 20:49 里列昂遗失的记事本 阅读(63) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; template<class T> class matrix { public: matrix(int theRows = 0, int theColumns = 0); matrix(const matrix<T> & 阅读全文
posted @ 2022-06-03 21:55 里列昂遗失的记事本 阅读(452) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; int main() { int numberOfRows = 5; // 定义每一行的长度 int length[5] = {6, 3, 4, 2, 7}; // 声明一个二维数组变量 // 分配所需要的行 int * 阅读全文
posted @ 2022-06-02 11:09 里列昂遗失的记事本 阅读(82) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; // 使用数组实现的并查集算法 int *equivClass;// 等价类数组 int n;//元素个数 void initialize(int numberOfElements) { // 用每个类的一个元素,初始化 阅读全文
posted @ 2022-06-02 11:02 里列昂遗失的记事本 阅读(128) 评论(0) 推荐(0)
摘要:箱排序 假定用一个链表保存一个班级学生清单。结点的数据有:学生姓名和考试分数。假设分数是0~100的整数。 采用箱排序可以把分数相同的结点放在同一个箱子里,然后把箱子连接起来就得到了有序的链表 链表定义 #include<iostream> #include <sstream> using name 阅读全文
posted @ 2022-06-01 21:24 里列昂遗失的记事本 阅读(40) 评论(0) 推荐(0)
摘要:#include<iostream> #include <sstream> using namespace std; class illegalParameterValue { public: illegalParameterValue() : message("Illegal parameter 阅读全文
posted @ 2022-05-28 22:35 里列昂遗失的记事本 阅读(43) 评论(0) 推荐(0)
摘要:#include<iostream> #include<vector> #include<sstream> using namespace std; class illegalParameterValue { public: illegalParameterValue() : message("Il 阅读全文
posted @ 2022-05-28 18:58 里列昂遗失的记事本 阅读(29) 评论(0) 推荐(0)
摘要:#include<iostream> #include <sstream> #include<iterator> #include<algorithm> using namespace std; // 重写copy代码 template<class iterator> void copy(itera 阅读全文
posted @ 2022-05-26 20:44 里列昂遗失的记事本 阅读(70) 评论(0) 推荐(0)
摘要:一元多项式的乘法与加法运算 设计函数分别求两个一元多项式的乘积与和 输入格式 输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。 输出格式 输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的 阅读全文
posted @ 2022-05-18 20:23 里列昂遗失的记事本 阅读(141) 评论(0) 推荐(0)
摘要:二叉搜索树的操作集 本题要求实现给定二叉搜索树的5种常用操作 函数接口定义 BinTree Insert( BinTree BST, ElementType X ); BinTree Delete( BinTree BST, ElementType X ); Position Find( BinTr 阅读全文
posted @ 2022-04-22 20:51 里列昂遗失的记事本 阅读(62) 评论(0) 推荐(0)
摘要:先序输出叶结点 本题要求按照先序遍历顺序输出给定二叉树的叶节点 函数接口定义 void PreorderPrintLeaves( BinTree BT ); 其中BinTree结构定义如下: typedef struct TNode *Position; typedef Position BinTr 阅读全文
posted @ 2022-04-22 20:18 里列昂遗失的记事本 阅读(80) 评论(0) 推荐(0)
摘要:求二叉树高度 本题要求给定二叉树的高度 函数接口定义 int GetHeight( BinTree BT ); 其中BinTree结构定义如下: typedef struct TNode *Position; typedef Position BinTree; struct TNode{ Eleme 阅读全文
posted @ 2022-04-22 20:11 里列昂遗失的记事本 阅读(97) 评论(0) 推荐(0)
摘要:#include<stdio.h> void Swap(int *x, int *y) { int t; t = *x; *x = *y; *y = t; } int Partition(int A[], int p, int r) { int X = A[p]; /* 选取第一个数为主元 主元不动 阅读全文
posted @ 2022-04-18 14:29 里列昂遗失的记事本 阅读(113) 评论(0) 推荐(0)
摘要:带头结点的链式表操作集 本题要求实现带头结点的链式表操作集 函数接口定义 Position Find( List L, ElementType X ); List Insert( List L, ElementType X, Position P ); List Delete( List L, Po 阅读全文
posted @ 2022-04-16 22:12 里列昂遗失的记事本 阅读(98) 评论(0) 推荐(0)
摘要:链式表操作集 本题要求实现链式表的操作集 函数接口定义 Position Find( List L, ElementType X ); List Insert( List L, ElementType X, Position P ); List Delete( List L, Position P 阅读全文
posted @ 2022-04-16 11:48 里列昂遗失的记事本 阅读(104) 评论(0) 推荐(0)
摘要:链式表的按序号查找 本题要求实现一个函数,找到并返回链式表的第K个元素、 函数接口定义 ElementType FindKth( List L, int K ); 其中List结构定义如下: typedef struct LNode *PtrToLNode; struct LNode { Eleme 阅读全文
posted @ 2022-04-15 19:37 里列昂遗失的记事本 阅读(95) 评论(0) 推荐(0)
摘要:求链式表的表长 本题要求实现一个函数,求链式表的表厂。 函数式接口定义 int Length( List L ); 其中List结构定义如下: typedef struct LNode *PtrToLNode; struct LNode { ElementType Data; PtrToLNode 阅读全文
posted @ 2022-04-15 16:07 里列昂遗失的记事本 阅读(59) 评论(0) 推荐(0)
摘要:顺序表操作集 本题要求实现顺序表的操作集 函数接口定义 List MakeEmpty(); Position Find( List L, ElementType X ); bool Insert( List L, ElementType X, Position P ); bool Delete( L 阅读全文
posted @ 2022-04-15 15:55 里列昂遗失的记事本 阅读(101) 评论(0) 推荐(0)