1 第五章    图
2 //结构定义
3 #define MaxVertexNum 100 //图中顶点数目的最大值
4 typedef struct ArcNode{ //边表节点
5 int adjvex; //该弧所指向的结点的位置
6 struct ArcNode *nextarc; //指向下一条边的指针
7 //InfoType info ; //网的边权值
8 }ArcNode;
9
10 typedef struct VNode{ //顶点表结点
11 VertexType data; //顶点信息
12 ArcNode *firstarc; //指向第一条依附该顶点的弧的指针
13 }VNode,AdjList[MaxVertexNum];
14
15 typedef struct{
16 AdjList vertices; //邻接表
17 int vexnum, arcnum; //图的顶点数和弧数
18 }ALGraph; //ALGraph是以邻接表存储的图类型
19
20
21
22
23
24 例1、已知G为邻接矩阵存储,请设计一个算法将其转换为 邻接表存储
25 void MatrixToAdj(int A[])
26 {
27 //初始化顶点表
28 for (int i=0;i<vertices;i++) //vertices 图中顶点数
29 {
30 adjList[i].firstarc = NULL; //firstarc指向第一条边的指针 adjList[]邻接表
31 }
32
33 //循环遍历邻接矩阵,当值为1时,则对顶点i后加上一个结点j
34 for (int i = 0 ; i < vertices ; i++)
35 {
36 for (int j = 0; j<vertices; j++)
37 {
38 if ( A[i][j] == 1)
39 {
40 ENode *p = (ENode*)malloc(sizeof(ENode)); //申请一个新的边结点
41 p->adjvex = j; //该边结点的指向的结点位置为j
42 p->nextarc = adjList[i].firstarc; //边结点指向的下一条边的指针指向第一条边结点
43 adjList[i].firstarc = p; //第一条边结点=p //这里采用了头插法
44 }
45 }
46 }
47 }
48
49 思考题:改成尾插法 考虑插第一个顶点和后续顶点的区别。
50
51
52 例2、邻接表转邻接矩阵 *****
53 void AdjToMatrix(Graph G)
54 {
55 int A[vertices][vertices];
56
57 for(int i = 0; i < vertices; i++) //将邻接矩阵清零
58 {
59 for (int j = 0; j < vertices; j++)
60 {
61 A[i][j] = 0;
62 }
63 }
64
65 for (int i = 0; i < G.vertices; i++) //
66 {
67 ENode *p = G.adjList[i].firstarc;
68 while(p!=NULL)
69 {
70 A[i][p->adjvex] = 1;
71 p = p->nextarc;
72 }
73 }
74 }
75
76
77
78 EX3、有向图G邻接表存储,计算各顶点的出度。 *****
79 #define int A[G.n] //置0
80 void Outcount(AGraph* G)
81 {
82 int i = 0; //用来计数
83 while(i < G.n)
84 {
85 VNode p = G.adjList[i];
86 ArcNode *q = p.firstarc;
87 while(q!=NULL)
88 {
89 A[i]++;
90 q=q->nextarc;
91 }
92 i++;
93 }
94 }
95
96 EX4、用邻接矩阵存储有向图,计算各节点入度出度 *****
97 //思想:邻接矩阵来计算度,就是遍历二维数组
98 //统计每行不为零的数,就是出度;每列不为零的数就是入度。
99 //使用两个数组一个存放入度,一个存放出度
100 #define outDegree[G.n]
101 #define inDegree[G.n]
102 void count(MGraph* G)
103 {
104 int A[G.n][G.n] = G.edges;
105 int i=j=0;
106 //出度
107 while(i < G.n)
108 {
109 while(j < G.n)
110 {
111 if (A[i][j] !=0)
112 outDegree[i]++;
113 j++;
114 }
115 i++;
116 }
117 //入度
118 while(j < G.n)
119 {
120 while(i < G.n)
121 {
122 if (A[i][j] !=0)
123 inDegree[j]++;
124 i++;
125 }
126 j++;
127 }
128
129 }
130
131 EX5
132 由邻接表存储方式的有向图,根据此,写出算法,输出其对应的邻接矩阵
133 //扫描邻接表中的所有边结点,然后根据其所连接的顶点号,将邻接矩阵对应位置设为1即可
134 void AGraphToMGraph(MGraph &g1, AGraph g2)
135 {
136 ArcNode *p;
137 int i,j;
138 //将g1的邻接矩阵清零
139 for (i=0;i<g1.n;++i)
140 for (j=0;j<g1.n;++j)
141 g1.edges[i][j] = 0;
142 /*使用p指针扫描邻接表中的所有边结点*/
143 for (i=0;i<g2.n;++i)
144 {
145 p= g2.adjList[i].firstarc;
146 while (p)
147 {
148 g1.edges[i][p->adjVex] = 1;
149 p = p->nextarc;
150 }
151 }
152 }
153
154
155 DS:计算各顶点的入度和出度 邻接表
156 void DegreeCount(LGraph *G,int inDegree[], int outDegree[])
157 //inDegree[]用来储存入度 outDegree[]用来储存出度
158 {
159 int i,count; //i表示顶点,count用来计数
160 ArcNode *p; //p指针用来扫描每个顶点所发出的边
161
162 for(i=0;i<G->n;i++) //将储存度的数组置零
163 inDegree[i]=outDegree[i]=0;
164
165 for(int i=0;i<G->n;i++)
166 {
167 count=0; //计数器清零
168 p=G->adjList[i].firstarc;
169 p=G->a[i];
170 while(p)
171 {
172 count++;
173 inDegree[p->adjVex]++;
174 }
175 outDegree[i]=count;
176 }
177 }
178
179 EX
180 写一个递归算法,在二叉树中搜索指定结点右孩子
181 如果有右孩子则返回右孩子的函数值并返回TRUE;若没有右孩子则返回FALSE
182 //想法,写两个函数体,一个主函数,一个递归程序,递归程序就是对遍历的该写
183 //同时还需要写一个搜索值,找到指定结点,判断其是否有右孩子,有就将有孩子的值赋给变量返回,没有就return false
184 #define int e
185 #define bool flage=false
186 bool searchRchlid(int X ,BTree * p)
187 {
188 if (p == NULL)
189 return false;
190 else
191 PreOrder(p,x);
192 return flage;
193 }
194 bool PreOrder(BTnode *p, int X)
195 {
196 if(p!= NULL)
197 {
198 if ( p->data == x)
199 {
200 if (p->Rchlid!=NULL)
201 e = p->Rchlid->data;
202 flage=ture;
203 }
204 break;
205 }
206 PreOrder(p->Lchlid,x);
207 PreOrder(P->Rchlid,x);
208 }
209 }
210
211
212 哈夫曼树加权路径长度
213 #define int sum = 0
214 #define int high = 0
215 void preorder(BTree *p)
216 {
217 if (p!=NULL)
218 {
219 if (p->lchild==NULL&&p->rchild==NULL)
220 sum = sum + p->element*high;
221 ++high;
222 preorder(p->lchild);
223 preorder(p->rchild);
224 --high;
225 }
226 }
227
228
229 用单链表实现简单选择排序
230 {void main(LNode *p)
231 {
232 LNode *flag = *p;
233 while (flag->next != NULL)
234 {
235 LNode *q = findMin(flag);
236 LNode *r = q->next;
237 q->next = r->next; //dd
238 r->next = flag->next;
239 flag->next=r;
240 flag=flag->next;
241 }
242 }
243 LNode findMin(LNode *flag)
244 {
245 LNode *min = flag;
246 LNode *r =flag;
247 while(r->next!=NULL)
248 {
249 if(r->next->data < min->next->data)
250 min = r;
251 r = r->next;
252 }
253 return min;
254 }}
255

tu

tu的更多相关文章

  1. HM中CU,TU的划分

    相信只要是做算法改进的,首先都会遇到这么一个问题:CU,PU及TU这几个在HM中该如何打印出它们最终的划分情况呢?也经常有人来问我这个问题,一般来说,因为问我的时候我一般手头都没有现成的代码可以提供, ...

  2. From missionary to firebrand--Eisle Tu [20160102]

    From missionary to firebrand   杜叶锡恩(1913年(癸丑年)-2015年(乙未年),英文名字Elsie Hume Elliot Tu,丈夫是教育家杜学魁.她是香港著名的 ...

  3. FFmpeg的HEVC解码器源代码简单分析:CTU解码(CTU Decode)部分-TU

    ===================================================== HEVC源代码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpe ...

  4. Telephone interview with Youyou Tu

    "Good News for the National Holiday!" Telephone interview with Youyou Tu following the ann ...

  5. Xiaoguang Tu's Home Page

    Xiaoguang Tu (涂晓光): CV: Ph.D. Candidate of School of Communication and Information Engineering, Univ ...

  6. 【HEVC简介】CTU、CU、PU、TU结构

     参考文献:见<High Efficiency Video Coding (HEVC)>Block Structures and Parallelism Features in HEVC章 ...

  7. .net core 使用Tu Share获取股票交易数据

     一.什么是Tu Share Tushare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采集.清洗加工 到 数据存储的过程,用户可以免费(部分数据的下载有积分限制)的通 ...

  8. Project Woosah Tu (五色土)

    I bought this Raspberry Pi (model B) in spring 2013, I hadn't done too much with it except for some ...

  9. 【团队冲刺总结】一个编码人员的反(tu)思(cao)

    消失了半个多月了啊,算算时间,好像确实有近个把月没有好好的写博客来了.我一直很想写博客的,之前有老师问过写博客的动力是什么.我想了想,我觉得可能是我比较喜欢看书吧,不管是专业书还是小说(好吧,我承认, ...

随机推荐

  1. 跨平台C# UI库

    https://github.com/AvaloniaUI/Avalonia https://www.cnblogs.com/leolion/p/7144896.html https://github ...

  2. 【HttpRunner v3.x】笔记 ——5. 测试用例-config

    上一篇中,我们了解到了config,在配置中,我们可以配置测试用例级级别的一些设置,比如基础url.验证.变量.导出. 我们一起来看,官方给出的一个例子: from httprunner import ...

  3. java 注解开发

    目录 注解 JDK自带的注解三个 注解分类 按照运行机制 按照来源分类 自定义注解的语法要求 元注解 解析注解 获取注解的注解 Spring中的注解 组合注解 注解 JDK自带的注解三个 @Overr ...

  4. Sequence (矩阵快速幂+快速幂+费马小定理)

            Holion August will eat every thing he has found. Now there are many foods,but he does not wa ...

  5. 递归方式---通过子级id,获取子级和父级Name

    #region 递归--返回 父级|子级 名称 #region --返回 父级|子级 名称 public string RetrurnTypeNames(string TypeId) { String ...

  6. 12_Python语法示例(函数)

    1.写一个函数mysum,此函数带有两个参数x,y打印出两个参数x,y的和 def mysum(x, y): print(x + y) mysum(3, 2) 2.写一个函数print_even,传入 ...

  7. ElasticSearch7.6.1 概述

    本来打算重新回去看 并发编程的,之前看过一遍,现在基本忘完了,然后因为考虑到项目的需要,就先看ES了 然后再B站上看到一个视屏比较火,就看这个吧 给大家推荐一下 https://www.bilibil ...

  8. Activiti7 流程变量(UEL-Value方式)

    需求:请假天数大于3天走总经理审批,小于等于3天直接走人事 画图 因为IDEA不展示那个线上的东西,所以截屏自己写的,还有就是我感觉IDEA画图挺坑的,之前画了好几遍,一部署就报错,很奇怪 /** * ...

  9. Linux系统小知识

    换Linux系统快半年了,刚开始总是碰到各种各样的问题,虽然斗解决了,由于没有记录,过一段时间就忘了,故在这里记录一下. 选择国内镜像源: Manjaro有一个很好用的命令rankmirrors.ra ...

  10. 初次使用maven创建web工程发现只有一个idea目录,src,webapp目录都不见了,解决方案

    修bug系列2之 初次使用maven创建web项目的src目录不知所踪 窗外下着下雨,屋内的我学着maven,本以为轻轻松松,没想到还是遇到了bug.好了不说了,来看看我是怎么解决的. 在初次使用ma ...