Posts

Showing posts with the label Code for Adjacency Maatrix
//C++ Code for adjacency matrix representation of graph and traversal on it .(DFS,Non-recursive //DFS and BFS)  #include<iostream> //#include<queue> //#include<stack> using namespace std; class graph {int G[10][10],n; int visit[10]; public: void create(); void bfs(); void dfs(int); void dfs1(); }; class stack { int st[10]; public: int top,v1; stack() { top=-1; } void push(int v1) { st[++top]=v1; } int pop() { v1=st[top]; top--; return v1; } }; class queue { public: int Q[10],v; int f,r; queue() { f=-1; r=-1; } void insert(int v) { if(f==-1&&r==-1) { f=0;r=0; Q[r]=v; } else{ r++; Q[r]=v; } } int del() { v=Q[f]; f++; return v; } }; void graph::create() {int e,i,j,v1,v2; cout<<"enter the no.of vertices"; cin>>n; cout<<"enter the no.of edges"; cin...