随笔分类 -  数据结构

剑指offer前6题
摘要:二维数组中的查找 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 时间限制:1秒 空间限制:32768K 热度指数:617731 本题知识点: 查找 思路:直接暴力查找即可,也可以 阅读全文
posted @ 2018-03-30 21:55 sapphirebitter 阅读(196) 评论(0) 推荐(0)
Calling Circles(UVa 247)(Floyd 算法)
摘要:用Floyd算法求出传递闭包,然后用dfs求出每条连通分量。注意其中用到的几个小技巧: 阅读全文
posted @ 2018-03-08 21:34 sapphirebitter 阅读(155) 评论(0) 推荐(0)
Keuskal算法模板
摘要:int cmp(const int i, const int j) { return w[i]<w[j]; }///间接比较函数,w[i]表示边i权值 int find_set(int x) { return p[x] == x ? x : p[x] = find_set(p[x]);} int Kruskal(){ int ans = 0; for (int i =... 阅读全文
posted @ 2017-11-22 22:21 sapphirebitter 阅读(204) 评论(0) 推荐(0)
无根树转有根树模板
摘要:vector G[maxn]; void read_tree(){ int u,v; scanf("%d",&n); for(int i = 0; i < n-1; i++){ scanf("%d%d",&u,&v); G[u].push_back(v);///输入u相邻的点v G[v].push_back(u); ... 阅读全文
posted @ 2017-11-15 20:55 sapphirebitter 阅读(168) 评论(0) 推荐(0)
Brute Force Sorting(HDU6215)
摘要:题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]<=a[i+1]。我们每次对当前数组删除非排序过的串,合并剩下的串,继续删,直到排序完成。 题解:用双向链表模拟删除过程即可。 具体细节见代码: 阅读全文
posted @ 2017-09-19 12:40 sapphirebitter 阅读(256) 评论(0) 推荐(0)
Tree Recovery
摘要:#include #include void build(int n,char*s1,char*s2) { if(n<=0)return ; int p=strchr(s2,s1[0])-s2;///p表示左结点的个数 build(p,s1+1,s2);///查找左结点 build(n-p-1,s1+p+1,s2+p+1);///查找右结点 printf(... 阅读全文
posted @ 2017-08-02 15:32 sapphirebitter 阅读(121) 评论(0) 推荐(0)
二叉树的非递归遍历
摘要:typedef struct BiTNode { char data; struct BiTNode *lchild, *rchild; ///左右孩子 } BiTNode,*BiTree; void PreOrder_Nonrecursive1(BiTree T) ///先序遍历的非递归 { if(!T) return ; ///如果结点为空,终止 ... 阅读全文
posted @ 2017-08-02 10:58 sapphirebitter 阅读(132) 评论(0) 推荐(0)
双向链表
摘要:题目: You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simulate 4 kinds of commands: • 1 X Y : move box X 阅读全文
posted @ 2017-08-01 17:14 sapphirebitter 阅读(142) 评论(0) 推荐(0)
链表
摘要:链表有2个储存单位,一个是数据存储单位value[maxn],一个是指示存储单位next[maxn],数据存储单位保存值,而next存储数据的顺序,每个next中存储的值即是下一个值所对应的next[i]中i的值,i的值对应value中数据的存储位置。 示例代码如下: 阅读全文
posted @ 2017-08-01 17:07 sapphirebitter 阅读(213) 评论(0) 推荐(0)
内存池技术(UVa 122 Tree on the level)
摘要:内存池技术就是创建一个内存池,内存池中保存着可以使用的内存,可以使用数组的形式实现,然后创建一个空闲列表,开始时将内存池中所有内存放入空闲列表中,表示空闲列表中所有内存都可以使用,当不需要某一内存时,将其放入空闲列表中,使内存可以循环使用。空闲列表可以用不定长数组vector定义,内存池和空闲列表的 阅读全文
posted @ 2017-08-01 16:16 sapphirebitter 阅读(239) 评论(0) 推荐(0)
二叉搜索树
摘要:#include using namespace std; const int maxn=105; int n; struct Node///建立结点,用结构体加指针,v表示结点的值 { int v; Node *left,*right;///用指针指向左子树和右子树 Node():left(NULL),right(NULL) {}///创建新结点 } tree ; No... 阅读全文
posted @ 2017-08-01 15:31 sapphirebitter 阅读(143) 评论(0) 推荐(0)