How to implement weighted graph using linked list?

We as usually implement the weighted graph using C++ STL . Is it possible to implement weight graph using linked list? If possible how?

Its possible either way. Since You stressed on using a linked list instead of c++ STL.
let me clarify a few things

In order to use a linked list. You have to make sure that the you either define a structure or a class having all the functionality that you use with a STL.

we use STL containers to represent a graph.

  • vector : A sequence container. Here we use it to store adjacency lists of all vertices.

  • pair : A simple container to store pair of elements. Here we use it to store adjacent vertex number and weight

However, It is possible to use a linked list.
Your code should look something like this or may vary as per your implementation.

struct Node{
int dist,weight;
Node*next;
};
struct Edge{
int src,dist,weight;
};
class Graph{
.......
}

This is the basic skeleton of the required implementation.
I think that’s enough to trigger the zeal in you to code it.
Happy coding!

1 Like

Probably this can help:

http://www.techiedelight.com/graph-implementation-c-without-using-stl/
one can refer to understand the basic implementation through structures

1 Like
//