Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Graph DFS
#include <bits/stdc++.h> using namespace std; #define MAX 7 struct Vertex{ int data; bool isVisited; }; stack<int> stk; vector<Vertex *> v; int vCount=0; int adjMat[MAX][MAX]; void addVertex(int data){ Vertex* newV = new Vertex(); newV->data = data; newV->isVisited = false; v.push_back(newV); vCount++; } void addEdge(int l, int r){ adjMat[l][r] = 1; adjMat[r][l] = 1; } void displayDFS(){ v[0]->isVisited = true; cout<<v[0]->data<<" "; } int main() { addVertex(0); addVertex(1); addVertex(2); addVertex(3); addVertex(4); addVertex(5); addVertex(6); cout<<vCount<<endl; addEdge(0,1); addEdge(0,2); addEdge(0,3); addEdge(1,4); addEdge(2,4); addEdge(3,5); addEdge(4,6); addEdge(5,6); for(int i=0;i<vCount;i++){ for(int j=0;j<vCount;j++) cout<<adjMat[i][j]<<" "; cout<<endl; } displayDFS(); return 0; }
run
|
edit
|
history
|
help
0
lambda demo
Bank System
decode
Test constructors and operators
inheritance
Updated Linked Lists - 5/10/2017 V4.0
c++_array_size
synowie abrahama
Deepa
sejmie