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. unity3d android动态更新dll

    基本是参考这篇文章:http://blog.sina.com.cn/s/blog_9e5d42ee0102vvtg.html,进行了增删一波. 大略说一下基本步骤:1.下载mono源码,修改源码,编译 ...

  2. 【平台开发】— 2.前端:vue-element-admin

    前端我虽然没怎么写过,但也并不陌生.之前做web自动化,网页结构没少看,html,css,js也都断断续续了解过. 如果从空白开始写,肯定还是需要花不少时间的. 好在网上有了不少成熟的后台系统的前端脚 ...

  3. 【BZOJ3453】XLkxc

    http://192.168.102.138/JudgeOnline/problem.php?id=3170 知识点:1.拉格朗日插值(多特殊函数相加) 2.这个式子看似非常复杂,然而只要明白这个式子 ...

  4. 详解 Python 的二元算术运算,为什么说减法只是语法糖?

    原题 | Unravelling binary arithmetic operations in Python 作者 | Brett Cannon 译者 | 豌豆花下猫("Python猫&q ...

  5. myeclipse前端界面乱码

    框起来的值默认的格式是ISO-8859-1,改为UTF-8

  6. SQL分词器1.10版

    处理SQL及分词效果: select * from ( select rownum as rn,tb1.stuid,tb1.summary from ( select stuid,sum(score) ...

  7. UEFI+MBR

    前言 传统情况下装系统的两种方案bios + mbr 或 uef i+ gpt but一直有一个疑问! 是否可以使用uefi + mbr 名词解释 硬盘格式 MBR分区:全称"Master ...

  8. roarctf_2019_easy_pwn

    这篇博客主要记录当直接在malloc_hook中直接写入one_gadget不起作用时的一些处理方法.题目附件:https://buuoj.cn/challenges#roarctf_2019_eas ...

  9. [LeetCode]Sql系列

    题目1 Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id. +----+-------+--------+--------------+ ...

  10. 内存管理初始化源码4:add_active_range

    我们在阅读源码时,函数功能可以分为两类:1. bootmem.c 2. page_alloc.c. 1. bootmem.c是关于bootmem allocator的,上篇文章已经简述过. 2. pa ...