//Syed Rais Ahmad //Assign 10 Ans 4. //Graphs #include "stdafx.h" #include class AdjMatrix { private: int adjMatrix[6][6]; public: bool reach(int,int); AdjMatrix(); }; AdjMatrix::AdjMatrix() { int i=0,j=0; for(;j<6;j++) { for(i=0;i<6;i++) adjMatrix[j][i]=0; } //Ones are put int the matrix to get graph with following arcs //<1,2><1,4><1,6><3,5><5,2><6,3> adjMatrix[0][1]=1; adjMatrix[0][3]=1; adjMatrix[0][5]=1; adjMatrix[2][4]=1; adjMatrix[4][1]=1; adjMatrix[0][1]=1; adjMatrix[5][2]=1; } bool AdjMatrix::reach(int n1,int n2) { if (n1 > 6 || n2 > 6) return false; if (n1==n2) return true; if (adjMatrix[n1-1][n2-1]) return true; return false; } int main(int argc, char* argv[]) { AdjMatrix am; cout << am.reach(4,2); cout << am.reach(3,6); cout << am.reach(6,3); return 0; }