Quick actions

cmd+k|ctrl+k

Navigation

Languages

Graph

Snippet info

Language

JavaScript

Visibility

public

Author

jameeulla3

Created

2024-08-09T03:14:26.281632Z

Updated

2024-08-09T17:24:43.289041Z

class Graph{
    constructor()
    {
        this.dataStore = [];
    }
    add_vertex(V)
    {
        this.dataStore[V] = [];
    }
    add_edge(v,e)
    {
        this.dataStore[v].push(e);
    }
    display()
    {
        for(let v=0;v<this.dataStore.length;v++)
        {
            for(let e=0;e<this.dataStore[v].length;e++)
            console.log(this.dataStore[v]+'->'+this.dataStore[v][e]);
        }
    }
}
let g = new Graph()
g.add_vertex('A')
g.add_vertex('B')
g.add_vertex('C')
g.add_edge('A', 'B')
g.add_edge('B', 'C')
g.add_edge('C', 'A')
g.display()
INFO