### How to implement Karger's Algorithm. Implemented the Graph DS so far. Need help.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134`` ``````#include using namespace std; //adjacency list representation. I have created a list of nodes and edges class graph { private: bool *color; int vertices; void addVertex(int u, int v) { node *temp=&ptr[u]; while(temp->next!=NULL) temp=temp->next; temp->next=new node(v); } public: class node { public: node(int name) { label=name; next=NULL; }; node(){next=NULL;}; int label; node *next; }; class edge { public: edge(int u, int v) { U=u; V=v; next=NULL; } int U,V; edge *next; }; node *ptr; edge *edgeList; edge *edgeTemp; graph(int V) { ptr=new node[V+1]; vertices=V; for(int i=1;i<=V;++i) ptr[i].label=i; color=new bool[vertices+1]; for(int i=0;i<=vertices;++i) color[i]=false; edgeList=NULL; } void addEdge(int u, int v) { addVertex(u,v); addVertex(v,u); if(!edgeList) { edgeList=new edge(u,v); edgeTemp=edgeList; } else { edgeTemp->next=new edge(u,v); edgeTemp=edgeTemp->next; } } void printEdges() { edge *temp=edgeList; while(temp) { cout<U<<"-"<V<next; } } void dfs(int vertex) { cout<next) { temp=temp->next; vertex=temp->label; if(!color[vertex]) dfs(vertex); } } }; int main() { graph Graph(8); Graph.addEdge(1,2); Graph.addEdge(1,3); Graph.addEdge(2,4); Graph.addEdge(2,6); Graph.addEdge(2,5); Graph.addEdge(3,7); Graph.addEdge(3,8); Graph.printEdges(); return 0x0; }``````

Please give me some hint regarding how to proceed with the Karger's Algorithm.
Also, is my code for the Graph DS okay? How would professional code this up?
Topic archived. No new replies allowed.