Java implementation of Graph adjacency table notation

Source: Internet
Author: User

In the course of learning algorithms, you will definitely encounter graphs. Because I am familiar with Java, so I am accustomed to use Java to implement it again, but I have not found the tree and figure data structure of the jar package, it is very regrettable.

Today search topology sorting implementation, inadvertently found a diagram of the Java implementation of "1", very good, founder than my own much better, map of the use is a bright spot:

Enum color {white, gray, black}static class vertex {private string  name;    private color color;      // Used to mark the processing state private vertex parent;    //search ends can get multiple trees private int discover;      //Start processing Time private int finish;       / /End Processing Time Public vertex (string name)  {this.name = name;this.color =  Color.White;} Public string getname ()  {return name;} Public void setname (String name)  {this.name = name;} Public color getcolor ()  {return color;} Public void setcolor (Color color)  {this.color = color;} Public vertex getparent ()  {return parent;} Public void setparent (vertex parent)  {this.parent = parent;} Public int getDiscover ()  {return discover;} Public void setdiscover (Int discover)  {this.discover = discover;} Public int getfinish ()  {return finish;} Public void setfinish (Int finish)  {this.finish = finish;} @Overridepublic  int hashcode ()  {final int prime = 31;int result =  1;result = prime * result +  ((Name == null)  ? 0 :  name.hashcode ()); return result;} @Overridepublic  boolean equals (object obj)  {if  (this == obj) return  true;if  (obj == null) return false;if  (GetClass ()  != obj.getclass ()) return  false; vertex other =  (Vertex)  obj;if  (name == null)  {if  (other.name  != null) Return false;}  else if  (!name.equals (other.name)) return false;return true;}}static class graph {private set<vertex> vertexset = new hashset <Vertex> ();//  adjacent nodes Private map<vertex, vertex[]> adjacencys = new  HashMap<Vertex, Vertex[]> ();p ublic set<vertex> getvertexset ()  {return  vertexset;} Public void setvertexset (Set<vertex> vertexset)  {this.vertexSet =  Vertexset;} Public map<vertex, vertex[]> getadjacencys ()  {return adjacencys;} Public void setadjacencys (Map<vertex, vertex[]> adjacencys)  {this.adjacencys  = adjacencys;}}

Attached to my own realization, silly according to the definition of the book, it is almost explosive:

public static class Alnode{public Alnode (String name) {this.name = name;} String name; Arcnode first;} public static class Arcnode{public Arcnode (Alnode node) {this.node = node;} Alnode node; Arcnode Next;} public static class Algraph{alnode nlist[];}

Resources

"1" Topology sort Java implementation http://blog.csdn.net/kimylrong/article/details/17220455

Java implementation of Graph adjacency table notation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.