Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int noOfVertex, size = 26, graph[50][50];
- char arr[size], chooceVertex;
- cout << "Enter Number of vertices: ";
- cin >> noOfVertex;
- for (int i = 0; i < size; i++) {
- arr[i] = 'A' + i;
- }
- // initialize the graph with 0
- for (int i = 0; i < noOfVertex; i++) {
- for (int j = i + 1; j < noOfVertex; j++) {
- graph[i][j] = 0;
- }
- }
- for (int i = 0; i < noOfVertex; i++) {
- for (int j = i + 1; j < noOfVertex; j++) {
- cout << arr[i] << "-" << arr[j] << ": ";
- scanf("%d", &graph[i][j]);
- if(graph[i][j] == 1) {
- graph[j][i] = 1;
- }
- }
- }
- cout << "Enter vertex: ";
- cin >> chooceVertex;
- cout << chooceVertex << "-> ";
- for (int i = 0; i < noOfVertex; i++) {
- if(graph[chooceVertex - 'A'][i] == 1) {
- cout << arr[i] << " ";
- }
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement