0% found this document useful (0 votes)
22 views1 page

Graph Utils

The document contains a Java class named GraphUtils that provides utility methods for converting graph-related objects to string representations. It includes methods to convert vertices and edges to strings, as well as to create specific string representations for vertices and edges within a graph. Additionally, it offers a method to convert all vertices from edges in a graph into a single string representation.

Uploaded by

Daniela Talmaciu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Graph Utils

The document contains a Java class named GraphUtils that provides utility methods for converting graph-related objects to string representations. It includes methods to convert vertices and edges to strings, as well as to create specific string representations for vertices and edges within a graph. Additionally, it offers a method to convert all vertices from edges in a graph into a single string representation.

Uploaded by

Daniela Talmaciu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

Edge;
import [Link];
import [Link];
import [Link];

public class GraphUtils {


// Convert vertex into String
public static <V, E> String toString(Vertex<V> vertex){
return [Link]().toString();
}
// Convert edge into String
public static <V, E> String toString(Edge<E> edge){
return [Link]().toString();
}
// Convert vertex of edge from graph into specifc String representation
public static <V, E> String toString(Vertex<V> vertex, Edge<E> ofEdge,
Graph<V,E> fromGraph){
String representation = [Link]() + "("
+ [Link](ofEdge)[0].getElement() + "-"
+ [Link](ofEdge)[1].getElement() + ","
+ [Link]()
+ "),";
return [Link]("),",")");
}
// Convert all vertexes from edges within graph
// into specific single String representation
public static <V, E> String toStringAll(Vertex<V> vertex,
PositionalList<Edge<E>> ofEdgePath,
Graph<V,E> fromGraph){
String representation = [Link]() + "[";
for (Edge<E> e: ofEdgePath) {
representation += [Link](e)[0].getElement()
+ "-" + [Link](e)[1].getElement()
+ "(" + [Link]() + ")" + ",";
}
representation += "]";
return [Link](",]", "]");
}
}

You might also like