图的邻接表存储及操作(含多接口实现)(Table adjacency table storage and operation (including multi interface implementation)).docVIP
- 4
- 0
- 约7.6千字
- 约 17页
- 2017-10-06 发布于河南
- 举报
图的邻接表存储及操作(含多接口实现)(Table adjacency table storage and operation (including multi interface implementation))
图的邻接表存储及操作(含多接口实现)(Table adjacency table storage and operation (including multi interface implementation))
import java.util. ;
/ / / / / / / / / / / / / / 二叉树的抽象数据类型定义
interface graph {
public boolean creategraph (edgeelement []); / / 建立图的存储结构
public int graphtype (); / / 返回图的类型
public int vertices (); / / 返回图中的顶点数
public int (); / / 返回图中的边数 edges
public boolean find (int i, int j); / / / / / / / / / / / / / / 从图中查找一条边 (i, j) 是否存在, 若存在则返回真否则返回假
/ / / / / / / / public boolean putedge (edgeelement theedge); / / 向图中插入一条边
/ / / / / / / / public boolean removeedge (int i, int j); / / / / / / / / / / / / / / 向图中删除一条边
public int (int i); / / / / / / / / / / / / / / / 返回顶点i的度
public int indegree (int i); / / 返回顶点i的入度
public int outdegree (int i); / / 返回顶点i的出度
public void output (); / / 以顶点集和边集的形式输出一个图
public void depthfirstsearch (int v); / / 从顶点v开始深度优先搜索遍历图
public void breadthfirstsearch (int v); / / 从顶点v开始广度优先搜索遍历图
void cleargraph (); / / 清除图中的所有内容
}
interface queue (
public boolean isempty()); / / 若为空表返回true, 否则返回false
public void connect (int obj); / / 结点 入队 (以编号表示)
public int (); / / 结点 was 出队 (以编号表示)
}
class edgeelement {/ / 定义边集数组中的元素类型
fromvex); / / 边的起点域
endvex); / / 边的终点域
int a; / / 边的权值域, 假定为整型, 对于无权图, 权值可为1
public int (int edgeelement v1, v2).
{/ / 对无权图中的边进行初始化
fromvex = v1 = v2, endvex; weight = 1.
}
public int (v1, v2) edgeelement, (wgt).
{/ / 对有权图中的边进行初始化
fromvex = v1 = v2, endvex; weight = wgt.
}
}
class adjacencygraph implements graph, line
{
final static int maxvalue = 1000); / / 一个不存在的边所使用的权值
final static int maxsize = 18.
private int n; / / 图的顶点数
private int e; / / 图的边数
private int type; / / 图的类型, 分别用0 - 3的值表示图的四种类型
private int [] []; / / 图的邻接矩阵, 假定元素类型为int
public int [] [] getarray () {return;} / / 返回邻接矩阵的引用
private int [] 存循环队列中的元素的数组 elem. / / / / / / / /
private int front, rear; / / 队头和队尾指针
public void initqueue () / / 初始化空队列
(when = new int [maxsize].
head = 0.
rear = 0}
public boolean isempty()) {
if (a = = true front ); / / 表空, 返回true
return false
您可能关注的文档
- 南开13秋学期《房地产法》在线作业(Nankai 13 autumn semester real estate law online homework).doc
- 南开大学12秋学期《基础会计学》在线作业1(Nankai University 12 autumn semester basic accounting online homework 1).doc
- 博弈金九银十 开发商一役难定乾坤(Game golden nine silver ten, developers battle is difficult to set the world).doc
- 博弈面试官评熟人(The game interviewer comments on acquaintances).doc
- 卡夫卡诗(Kafka Shi).doc
- 卡巴斯基国外服务器升级地址和方法(Kabasiji overseas server upgrade addresses and methods).doc
- 博士考试的策略(Strategies for doctoral examinations).doc
- 卢展工以新型城镇化带动三化协调发展--河南新闻 -中新网河南新闻(Lu Zhangong to promote the coordinated development of three urbanization with new urbanization -- Henan News - Henan news).doc
- 南越总统吴庭艳(South Vietnamese President Wu Tingyan).doc
- 南洋珍珠(Nanyang Pearl).doc
最近下载
- 2025年长沙市中考地理试卷真题(含答案详解).pdf
- 视听语言PPT课件(共8单元)第一章.pptx VIP
- 马克思主义发展史PPT全套课件.pptx
- 《心脏的解剖与功能》课件.ppt VIP
- DB53_T 1229-2024 暗褐脉柄牛肝菌菌种生产技术规程.pdf VIP
- 《马克思主义发展史》课程教学大纲.doc VIP
- 《马克思主义发展史》课程教学大纲.docx VIP
- 服务心理学(第四版)课件 项目二 服务心理学.pptx
- (对照贯彻党的创新理论方面,对照加强党性锤炼方面,对照联系服务群众方面,对照发挥先锋模范作用方面,对照改作风树新风方面)基层党员2025年度组织生活会个人对照检查(五个对照).docx VIP
- 2025年甘肃三支一扶考试公共基础知识真题及答案.docx VIP
原创力文档

文档评论(0)