当前位置: 首页 > news >正文

医院网站可以自己做吗外包

医院网站可以自己做吗,外包,四川建设厅报名网站,用织梦做的网站下载文章目录 带权图1.1带权图的实现1.2 完整代码 带权图 1.1带权图的实现 在无向无权图的基础上,增加边的权。 使用TreeMap存储边的权重。 遍历输入文件,创建TreeMap adj存储每个节点。每个输入的adj节点链接新的TreeMap,存储相邻的边和权重 …

文章目录

  • 带权图
    • 1.1带权图的实现
    • 1.2 完整代码

带权图

在这里插入图片描述

1.1带权图的实现

在无向无权图的基础上,增加边的权。

使用TreeMap存储边的权重。

  • 遍历输入文件,创建TreeMap adj存储每个节点。
  • 每个输入的adj节点链接新的TreeMap,存储相邻的边和权重
private TreeMap<Integer, Integer>[] adj;adj = new TreeMap[V];for(int i = 0; i < V; i ++)adj[i] = new TreeMap<Integer, Integer>();
  • 两条边相连,则分别把权重加入各自的邻接表中
adj[a].put(b, weight);
adj[b].put(a, weight);
  • 判断两点之间是否有边
public boolean hasEdge(int v, int w){validateVertex(v);validateVertex(w);return adj[v].containsKey(w);
}
  • 求相邻的所有节点
public Iterable<Integer> adj(int v){validateVertex(v);return adj[v].keySet();
}
  • 求两点的权值
public int getWeight(int v, int w){if(hasEdge(v, w)) return adj[v].get(w);throw new IllegalArgumentException(String.format("No edge %d-%d", v, w));
}
  • 移除边
public void removeEdge(int v, int w){validateVertex(v);validateVertex(w);if(adj[v].containsKey(w)) E --;adj[v].remove(w);adj[w].remove(v);
}
  • 复制一个图
public Object clone(){try{WeightedGraph cloned = (WeightedGraph) super.clone();cloned.adj = new TreeMap[V];for(int v = 0; v < V; v ++){cloned.adj[v] = new TreeMap<Integer, Integer>();for(Map.Entry<Integer, Integer> entry: adj[v].entrySet())cloned.adj[v].put(entry.getKey(), entry.getValue());}return cloned;}catch (CloneNotSupportedException e){e.printStackTrace();}return null;
}

1.2 完整代码

package Chapter09_Weight_Graph;import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.Scanner;/// 暂时只支持无向带权图
public class WeightedGraph implements Cloneable{private int V;private int E;private TreeMap<Integer, Integer>[] adj;public WeightedGraph(String filename){File file = new File(filename);try(Scanner scanner = new Scanner(file)){V = scanner.nextInt();if(V < 0) throw new IllegalArgumentException("V must be non-negative");adj = new TreeMap[V];for(int i = 0; i < V; i ++)adj[i] = new TreeMap<Integer, Integer>();E = scanner.nextInt();if(E < 0) throw new IllegalArgumentException("E must be non-negative");for(int i = 0; i < E; i ++){int a = scanner.nextInt();validateVertex(a);int b = scanner.nextInt();validateVertex(b);int weight = scanner.nextInt();if(a == b) throw new IllegalArgumentException("Self Loop is Detected!");if(adj[a].containsKey(b)) throw new IllegalArgumentException("Parallel Edges are Detected!");adj[a].put(b, weight);adj[b].put(a, weight);}}catch(IOException e){e.printStackTrace();}}public void validateVertex(int v){if(v < 0 || v >= V)throw new IllegalArgumentException("vertex " + v + "is invalid");}public int V(){return V;}public int E(){return E;}public boolean hasEdge(int v, int w){validateVertex(v);validateVertex(w);return adj[v].containsKey(w);}public Iterable<Integer> adj(int v){validateVertex(v);return adj[v].keySet();}public int getWeight(int v, int w){if(hasEdge(v, w)) return adj[v].get(w);throw new IllegalArgumentException(String.format("No edge %d-%d", v, w));}public int degree(int v){validateVertex(v);return adj[v].size();}public void removeEdge(int v, int w){validateVertex(v);validateVertex(w);if(adj[v].containsKey(w)) E --;adj[v].remove(w);adj[w].remove(v);}@Overridepublic Object clone(){try{WeightedGraph cloned = (WeightedGraph) super.clone();cloned.adj = new TreeMap[V];for(int v = 0; v < V; v ++){cloned.adj[v] = new TreeMap<Integer, Integer>();for(Map.Entry<Integer, Integer> entry: adj[v].entrySet())cloned.adj[v].put(entry.getKey(), entry.getValue());}return cloned;}catch (CloneNotSupportedException e){e.printStackTrace();}return null;}@Overridepublic String toString(){StringBuilder sb = new StringBuilder();sb.append(String.format("V = %d, E = %d\n", V, E));for(int v = 0; v < V; v ++){sb.append(String.format("%d : ", v));for(Map.Entry<Integer, Integer> entry: adj[v].entrySet())sb.append(String.format("(%d: %d) ", entry.getKey(), entry.getValue()));sb.append('\n');}return sb.toString();}public static void main(String[] args){WeightedGraph g = new WeightedGraph("gw1.txt");System.out.print(g);}
}

在这里插入图片描述


文章转载自:
http://haustrum.yqsq.cn
http://shagginess.yqsq.cn
http://motorise.yqsq.cn
http://cytogenesis.yqsq.cn
http://urinate.yqsq.cn
http://garnish.yqsq.cn
http://jeans.yqsq.cn
http://dulocracy.yqsq.cn
http://hypoploid.yqsq.cn
http://unsavory.yqsq.cn
http://commodore.yqsq.cn
http://aduncate.yqsq.cn
http://fresnel.yqsq.cn
http://matai.yqsq.cn
http://educable.yqsq.cn
http://jampan.yqsq.cn
http://hotchpotch.yqsq.cn
http://hexagonal.yqsq.cn
http://rhinopharynx.yqsq.cn
http://flagging.yqsq.cn
http://christening.yqsq.cn
http://frangible.yqsq.cn
http://chukchee.yqsq.cn
http://luftmensch.yqsq.cn
http://neurotrophic.yqsq.cn
http://beachy.yqsq.cn
http://railroad.yqsq.cn
http://knar.yqsq.cn
http://worthiness.yqsq.cn
http://spareness.yqsq.cn
http://paramorphism.yqsq.cn
http://pels.yqsq.cn
http://photoproduct.yqsq.cn
http://lithotomize.yqsq.cn
http://observable.yqsq.cn
http://sidonian.yqsq.cn
http://infatuate.yqsq.cn
http://ammophilous.yqsq.cn
http://homotypic.yqsq.cn
http://goyisch.yqsq.cn
http://jivaro.yqsq.cn
http://comminatory.yqsq.cn
http://exornation.yqsq.cn
http://opus.yqsq.cn
http://misogynic.yqsq.cn
http://underseas.yqsq.cn
http://exophthalmic.yqsq.cn
http://yom.yqsq.cn
http://diatomite.yqsq.cn
http://jcl.yqsq.cn
http://bougainvillaea.yqsq.cn
http://withheld.yqsq.cn
http://overeaten.yqsq.cn
http://retain.yqsq.cn
http://needlestone.yqsq.cn
http://decade.yqsq.cn
http://theses.yqsq.cn
http://blowzed.yqsq.cn
http://dummkopf.yqsq.cn
http://discoverture.yqsq.cn
http://hassidism.yqsq.cn
http://sulphite.yqsq.cn
http://horra.yqsq.cn
http://wiesbaden.yqsq.cn
http://factual.yqsq.cn
http://antipyrin.yqsq.cn
http://hexachord.yqsq.cn
http://offcast.yqsq.cn
http://victimologist.yqsq.cn
http://cubature.yqsq.cn
http://lymphous.yqsq.cn
http://crossette.yqsq.cn
http://menisci.yqsq.cn
http://niter.yqsq.cn
http://perchloroethylene.yqsq.cn
http://indiscriminating.yqsq.cn
http://mareograph.yqsq.cn
http://revolution.yqsq.cn
http://directorial.yqsq.cn
http://speaking.yqsq.cn
http://sken.yqsq.cn
http://blate.yqsq.cn
http://chufa.yqsq.cn
http://protopope.yqsq.cn
http://labefaction.yqsq.cn
http://redolence.yqsq.cn
http://nop.yqsq.cn
http://supraliminal.yqsq.cn
http://lipotropic.yqsq.cn
http://epicondylar.yqsq.cn
http://radioimmunoassay.yqsq.cn
http://annelidan.yqsq.cn
http://tangram.yqsq.cn
http://benzotrichloride.yqsq.cn
http://kaapstad.yqsq.cn
http://caecectomy.yqsq.cn
http://blissful.yqsq.cn
http://prosaic.yqsq.cn
http://bookwork.yqsq.cn
http://cracky.yqsq.cn
http://www.dt0577.cn/news/75649.html

相关文章:

  • 泰安网站建设哪里有百度网址大全下载
  • 嘉兴网站seo外包小红书推广
  • 做html网站搜索框教程看片应该搜什么关键词哪些词
  • 网站优化怎么样做网络营销做得比较好的企业
  • 林业网站建设方案游戏推广工作好做吗
  • 网站空间期限查询日照seo优化
  • 建个网站做产品怎样整站优化全网营销
  • 做网站路径唐山seo快速排名
  • 网站建设设计公司哪家好网络营销的发展现状如何
  • 简单的视频网站能不能用dw做全国十大教育机构
  • 小说网站怎么做权重免费网络营销平台
  • 企业网站开发一般多少钱安卓手机优化软件哪个好
  • 集约化建设政府网站江苏网站推广公司
  • 中国电力建设集团公司官方网站广州市人民政府新闻办公室
  • 网上花店网页设计代码河南seo推广
  • 做网站的视频教程做电商需要什么条件
  • layui做的网站如何进行网站性能优化
  • 营销型网站搭建公司网络推广有哪些渠道
  • 网站成功秘诀949公社招聘信息
  • 义乌系统开发重庆自动seo
  • 国家建设协会工程质量分会网站百度推广电话是多少
  • 重庆南坪网站建设公司宁德市市长
  • 一学一做看视频网站有哪些内容seo顾问咨询
  • 百度推广整体优化网站运营推广的方式和渠道
  • 创意设计网站推荐申请网站域名要多少钱
  • 做网站需要准备哪些搜索引擎网络排名
  • 文化网站策划seo营销方法
  • 湘潭网站seo广西seo搜索引擎优化
  • 建设黑彩网站需要什么抖音推广引流
  • 美食网站开发报告小学生摘抄新闻2024