Giter Club home page Giter Club logo

java-dijkstra's Introduction

基于Java实现的Dijkstra 最短路径的实现.

public void demo1() {
	//声明点
	Point A = new MyPoint(1,0,0);
	Point B = new MyPoint(2,0,0);
	Point C = new MyPoint(3,0,0);
	Point D = new MyPoint(4,0,0);
	Point E = new MyPoint(5,0,0);
	//放入点集合
	ArrayList<Point> source = new ArrayList<Point>();
	source.add(A);
	source.add(B);
	source.add(C);
	source.add(D);
	source.add(E);
	//声明边
	ArrayList<Edge> edges = new ArrayList<Edge>();
	edges.add(new Edge(A, B, 10));
	edges.add(new Edge(A, C, 5));
	edges.add(new Edge(B, C, 2));
	edges.add(new Edge(B, D, 1));
	edges.add(new Edge(C, B, 3));
	edges.add(new Edge(C, D, 9));
	edges.add(new Edge(C, E, 2));
	edges.add(new Edge(D, E, 4));
	edges.add(new Edge(E, D, 6));
	edges.add(new Edge(E, A, 7));
	Dijkstra d = new Dijkstra();
	Stack<Point> points = d.dijkstra(source, edges, A, D);//提供 点的集合 边的集合 起点 终点 开始寻径
	while (points.size() > 0) {
		Point p = points.pop(); 
		System.out.print(((MyPoint)p).getId()+">");//打印 打印结果 : 1>3>2>4
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.