-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2_Lab_10.cpp
More file actions
61 lines (45 loc) · 1.04 KB
/
q2_Lab_10.cpp
File metadata and controls
61 lines (45 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include<list>
using namespace std;
struct Node{
int label;
list<int> neighbours ;
};
struct Graph{
int n=8;
Node * nodes = new Node[n];
void intializenodes(){
for(int i=0;i<n;i++){
nodes[i].label=i;
}
}
void addedge(int u, int v) {
nodes[u].neighbours.push_back(v);
}
void print(){
for (int i = 0; i < n; i++) {
cout << "Node " << (nodes[i].label) + 1 << ": ";
for (int neighbour : nodes[i].neighbours) {
cout << neighbour << " ";
}
cout << endl;
}
}
};
int main() {
Graph * g = new Graph;
g->intializenodes();
g->addedge(1,2);
g->addedge(1,3);
g->addedge(1,4);
g->addedge(1,5);
g->addedge(2,3);
g->addedge(2,6);
g->addedge(4,6);
g->addedge(4,7);
g->addedge(4,8);
g->addedge(5,6);
g->addedge(5,7);
g->addedge(5,8);
g->print();
}