
数据结构
Dilly__dally
这个作者很懒,什么都没留下…
展开
-
链式表操作集
6-5 链式表操作集(20 分)本题要求实现链式表的操作集。函数接口定义:Position Find( List L, ElementType X );List Insert( List L, ElementType X, Position P );List Delete( List L, Position P );其中List结构定义如下:typedef struc...原创 2018-07-28 21:59:38 · 777 阅读 · 1 评论 -
二叉搜索树的操作集
6-12 二叉搜索树的操作集(30 分)本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position...原创 2018-08-24 21:07:41 · 238 阅读 · 0 评论 -
UVA 122(二叉树+字符串输入)
题意:给你一颗二叉树上面的若干节点上的值(均为正数),判断从根到所有的给定的点的路径上的节点,是不是都有值,且只被赋值一次。思路:这题不难,主要是一些细节上的处理,学习一下。。#include<bits/stdc++.h>using namespace std;#define inf 0x3f3f3f3f#define ll long longconst int ...原创 2018-08-31 19:30:44 · 465 阅读 · 0 评论 -
二叉树重构(知后序中序求前序)
#include<bits/stdc++.h>using namespace std;#define inf 0x3f3f3f3f#define ll long long#define fo freopen("in.txt","r",stdin)#define fc fclose(stdin)#define fu0(i,n) for(i=0;i<n;i++)#de...原创 2018-07-19 17:27:54 · 236 阅读 · 0 评论 -
先序输出叶子结点
6-11 先序输出叶结点(15 分)本题要求按照先序遍历的顺序输出给定二叉树的叶结点。函数接口定义:void PreorderPrintLeaves( BinTree BT );其中BinTree结构定义如下:typedef struct TNode *Position;typedef Position BinTree;struct TNode{ Elemen...原创 2018-08-24 11:46:12 · 806 阅读 · 0 评论 -
二叉树求高度
#include<bits/stdc++.h>using namespace std;typedef char ElementType;typedef struct TNode *Position;typedef Position BinTree;struct TNode{ ElementType Data; BinTree Left; BinTre...原创 2018-08-24 10:54:16 · 328 阅读 · 0 评论 -
POJ1849 Two(树的直径)
题意:有一颗n个结点的带权的无向树, 在s结点放两个机器人, 这两个机器人会把树的每条边都走一遍, 但是最后机器人不要求回到出发点. 问你两个机器人走的路总长之和的最小值是多少?思路:考虑从一个结点遍历整个树再回到原点需要把每个边计算两遍,这里机器人不用回到出发点,所以两个机器人到达的点越远越好。让两个机器人在初始位置在直径上背道而驰,这样最优解就是所有边*2-直径,因为直径只走了一次,而其他...原创 2018-08-31 00:10:45 · 482 阅读 · 0 评论 -
【模板】树的直径(树的最长路)
具体学习参考https://blog.youkuaiyun.com/qq_32400847/article/details/51469917#include<queue>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algo...原创 2018-08-30 23:33:16 · 205 阅读 · 0 评论 -
PAT Advanced Level 1102二叉树反转
#include<bits/stdc++.h>using namespace std;#define inf 0x3f3f3f3f#define ll long longconst int maxn=200005;const double eps=1e-8;const double PI = acos(-1.0);#define lowbit(x) (x&(-x...原创 2018-08-26 15:11:15 · 179 阅读 · 1 评论 -
顺序表操作集
6-2 顺序表操作集(20 分)本题要求实现顺序表的操作集。函数接口定义:List MakeEmpty(); Position Find( List L, ElementType X );bool Insert( List L, ElementType X, Position P );bool Delete( List L, Position P );其中List结...原创 2018-07-27 10:46:58 · 522 阅读 · 0 评论 -
在一个数组中实现两个堆栈
6-7 在一个数组中实现两个堆栈(20 分)本题要求在一个数组中实现两个堆栈。函数接口定义:Stack CreateStack( int MaxSize );bool Push( Stack S, ElementType X, int Tag );ElementType Pop( Stack S, int Tag );其中Tag是堆栈编号,取1或2;MaxSize堆栈数组的...原创 2018-07-29 19:55:48 · 283 阅读 · 0 评论 -
二叉树四种遍历
void PreorderTraversal(BinTree BT){ if(BT==NULL) return; printf(" %c",BT->Data); PreorderTraversal(BT->Left); PreorderTraversal(BT->Right);}void InorderTraversal(BinTree BT){...原创 2018-07-21 10:46:59 · 339 阅读 · 0 评论 -
单链表逆转
List Reverse( List L ){ List p,q; p=L; L=NULL; while(p){ q=p; p=p->Next; q->Next=L; L=q; } return L;}原创 2018-07-21 09:37:27 · 147 阅读 · 0 评论 -
散列——分离链接法
来自《数据结构与算法 王立柱》//HashTable.h#include<list>#include<vector>#include<iomanip>#include<algorithm>using namespace std;template<class Iterator,class T>Iterator Find(...原创 2018-11-26 09:28:50 · 236 阅读 · 0 评论