Niloy007

DS Code

May 18th, 2020
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.     int noOfVertex, size = 26, graph[50][50];
  7.     char arr[size], chooceVertex;
  8.  
  9.     cout << "Enter Number of vertices: ";
  10.     cin >> noOfVertex;
  11.     for (int i = 0; i < size; i++) {
  12.         arr[i] = 'A' + i;
  13.     }
  14.  
  15.     // initialize the graph with 0
  16.     for (int i = 0; i < noOfVertex; i++) {
  17.         for (int j = i + 1; j < noOfVertex; j++) {
  18.             graph[i][j] = 0;
  19.         }
  20.     }
  21.  
  22.  
  23.     for (int i = 0; i < noOfVertex; i++) {
  24.         for (int j = i + 1; j < noOfVertex; j++) {
  25.                 cout << arr[i] << "-" << arr[j] << ": ";
  26.                 scanf("%d", &graph[i][j]);
  27.                 if(graph[i][j] == 1) {
  28.                     graph[j][i] = 1;
  29.                 }
  30.         }
  31.     }
  32.  
  33.     cout << "Enter vertex: ";
  34.     cin >> chooceVertex;
  35.  
  36.     cout << chooceVertex << "-> ";
  37.     for (int i = 0; i < noOfVertex; i++) {
  38.         if(graph[chooceVertex - 'A'][i] == 1) {
  39.             cout << arr[i] << " ";
  40.         }
  41.     }
  42.     cout << endl;
  43.  
  44.     return 0;
  45. }
RAW Paste Data