|
1 #include <iostream> |
|
2 #include <graph.h> |
|
3 |
|
4 using namespace NEGRO; |
|
5 using namespace std; |
|
6 |
|
7 class NodeData; |
|
8 class EdgeData; |
|
9 |
|
10 typedef Graph<NodeData,EdgeData> TestGraph; |
|
11 |
|
12 class NodeData |
|
13 { |
|
14 public: |
|
15 int id; |
|
16 bool isVis; |
|
17 }; |
|
18 |
|
19 class EdgeData |
|
20 { |
|
21 public: |
|
22 int id; |
|
23 }; |
|
24 |
|
25 |
|
26 typedef Graph<NodeData,EdgeData> TestGraph; |
|
27 |
|
28 void main() |
|
29 { |
|
30 TestGraph G; |
|
31 TestGraph::NodeIterator n,m,o,p,q; |
|
32 TestGraph::OutEdgeIterator e,f,g,h; |
|
33 int i,j,k; |
|
34 |
|
35 |
|
36 //for(i=1;i<=10;i++) G.AddNode().n=i; //Ez nagyon rossz!!!!!!!! |
|
37 for(i=1;i<=10;i++) G.AddNode()->id=i; //Ez a jo!!!!!!!! |
|
38 |
|
39 //n=G.AddNode(); |
|
40 |
|
41 //for(i=1;i<=10;i++) cout << (G.AddNode()->n=i) << ' '; |
|
42 //cout << '\n'; |
|
43 |
|
44 i=0; |
|
45 for(G.GetFirst(n);n.isValid();n++) |
|
46 for(G.GetFirst(m);m.isValid();++m) |
|
47 if(n!=m) G.AddEdge(n,m)->id=++i; |
|
48 |
|
49 cout << "Number of edges: " << i << "\n\n"; |
|
50 |
|
51 TestGraph::AllEdgeIterator a; |
|
52 for(G.GetFirst(a);a.isValid();++a) |
|
53 cout << a->id << ":" << a.From()->id << "->" << a.To()->id << " "; |
|
54 |
|
55 cout << "\n\n\n"; |
|
56 |
|
57 for(G.GetFirst(n);n.isValid();++n) |
|
58 { |
|
59 cout << n->id << "->"; |
|
60 for(G.GetFirst(e,n);e.isValid();++e) |
|
61 cout << e->id << ":" << e.To()->id << ' '; |
|
62 cout << '\n'; |
|
63 } |
|
64 |
|
65 cout << "\n\n\n\nB-verzio:\n\n\n"; |
|
66 |
|
67 G.Clean(); |
|
68 |
|
69 for(i=1;i<=10;i++) G.AddNode()->id=i; |
|
70 |
|
71 i=0; |
|
72 for(n=G.First();n.isValid();n++) |
|
73 for(m=G.First();m.isValid();++m) |
|
74 if(n!=m) G.AddEdge(n,m)->id=++i; |
|
75 |
|
76 ; |
|
77 for(n=G.First();n.isValid();++n) |
|
78 { |
|
79 e=G.First(n); |
|
80 while(e.isValid()) |
|
81 if((e->id)%2) G.Delete(e++); |
|
82 else ++e; |
|
83 } |
|
84 |
|
85 for(a=G.First();a.isValid();++a) |
|
86 cout << a->id << ": " << a.From()->id << "->" << a.To()->id << " "; |
|
87 |
|
88 cout << "\n\n\n"; |
|
89 |
|
90 for(n=G.First();n.isValid();++n) |
|
91 { |
|
92 cout << n->id << "->"; |
|
93 for(e=G.First(n);e.isValid();++e) |
|
94 cout << e->id << ":" << e.To()->id << ' '; |
|
95 cout << '\n'; |
|
96 } |
|
97 |
|
98 } |