网站大量收购独家精品文档,联系QQ:2885784924

数据结构图的建立与计算(Establishment and calculation of data structure diagram).doc

数据结构图的建立与计算(Establishment and calculation of data structure diagram).doc

  1. 1、本文档共46页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构图的建立与计算(Establishment and calculation of data structure diagram) # includes stdio.h # includes stdlib.h # includes math.h # includes malloc.h # includes string.h # define null 0 # define infinity 2000 / / 权值很大, 表示两顶点不相关联 # define max 20 / / 图顶点数目最大值 # define namelength 20 / / 顶点名称字符串容许的最大字符个数 typedef enum value { dg, dn, udg, udn / / {有向图, 有向网, 无向图, 无向网} } graphkind; typedef struct arccell { int adj; / / 无权图, 用1和0表示相邻否, 对带权图, 为权值 char *); / / 该弧相关信息的指针 } arccell, adjmatrix [max] [max]. typedef struct { char vexs [max] [namelength]; / / 顶点名称 adjmatrix arcs; / / 邻接矩阵 int vexnum, arcnum; / / 图的当前顶点数和弧数 graphkind kind; / / 图的种类标志 } mgraph; typedef struct qnode { int date; struct qnode * next; } qnode, * queueptr; / / 队列的结点结构体, 存储的是指向二叉树结点的指针 typedef struct { queueptr front; queueptr rear; linkqueue}; / / 该结构体含指向队头的指针和队尾的指针 / / 新建一个队列 void initqueue (linkqueue q) { q.front = q.rear = (queueptr) malloc (sizeof (qnode)); q.front - next = null; } / / 将一个元素t插入队列 void enqueue (linkqueue q, int i) { queueptr p; p = (queueptr) malloc (sizeof (qnode)); p - date = i; p - next = null; q.rear - next = p; q.rear = p; } / / 将一个元素从队列中删除, 返回该元素 int dequeue (linkqueue q, int ) { queueptr p; if (q.front = = q.rear) return 0; p = q.front - next; i = p - date; q.front - next = p - next; if (q.rear = = p) q.rear = q.front; free (p). return 1; } / / 判断队列是否为空, 若为空, 返回1, 若不为空, 则返回0 int queueempty (linkqueue q) { if (q.front = = q.rear) return 1; else return 0; } / / 取得队头元素 int gethead (linkqueue q) { return (q.front - next - date); } / / 定位函数, 求得字符串v在图g中的顶点序号, 若不存在, 返回 - 1, 若存在, 返回该序号 int locatevex (mgraph g, char v [5]) { int i; for (i = 0; i g.vexnum; i + +) if (strcmp (g.vexs [], v) = = 0) return 1; / / 查找 printf (该顶点不存在! \ n); return - 1; } This function is used for / / the first vertex and the number of G in Figure V (due to the vertex associated graph representation, so it has relation with adjacency matrix, / / returns the index of the vertex Int FirstAdjVex

文档评论(0)

f8r9t5c + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8000054077000003

1亿VIP精品文档

相关文档