图的邻接表存储及操作(含多接口实现)(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)).doc

图的邻接表存储及操作(含多接口实现)(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

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档