Showing posts with label Graph. Show all posts
Showing posts with label Graph. Show all posts

Monday, November 9, 2015

Graph implementation using linkedlists

Here's my python class
(Includes class Node and class Graph)
https://raw.githubusercontent.com/prabushitha/DataStructures/master/Graph/GraphAL.py

Usage
#After copying/importing above 2 classes to your code

#Creating a new graph

graph = Graph()

#Adding a vertex. e.g add 2 vertexes A and B
graph.addVertex("A")
graph.addVertex("B")

#Adding an edge between 2 vertexes 
graph.addEdge("A","B")

#Check whether there's an edge between 2 vertexes. e.g from A to B (returns True/False)
graph.isEdge("A","C")
#Check whether there's a path from one vertex to another. e.g from A to B (returns True/False)
graph.isPath("D","B")