1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/graphdemo.cc Sat Dec 06 19:32:27 2003 +0000
1.3 @@ -0,0 +1,98 @@
1.4 +#include <iostream>
1.5 +#include <graph.h>
1.6 +
1.7 +using namespace NEGRO;
1.8 +using namespace std;
1.9 +
1.10 +class NodeData;
1.11 +class EdgeData;
1.12 +
1.13 +typedef Graph<NodeData,EdgeData> TestGraph;
1.14 +
1.15 +class NodeData
1.16 +{
1.17 +public:
1.18 + int id;
1.19 + bool isVis;
1.20 +};
1.21 +
1.22 +class EdgeData
1.23 +{
1.24 +public:
1.25 + int id;
1.26 +};
1.27 +
1.28 +
1.29 +typedef Graph<NodeData,EdgeData> TestGraph;
1.30 +
1.31 +void main()
1.32 +{
1.33 + TestGraph G;
1.34 + TestGraph::NodeIterator n,m,o,p,q;
1.35 + TestGraph::OutEdgeIterator e,f,g,h;
1.36 + int i,j,k;
1.37 +
1.38 +
1.39 + //for(i=1;i<=10;i++) G.AddNode().n=i; //Ez nagyon rossz!!!!!!!!
1.40 + for(i=1;i<=10;i++) G.AddNode()->id=i; //Ez a jo!!!!!!!!
1.41 +
1.42 + //n=G.AddNode();
1.43 +
1.44 + //for(i=1;i<=10;i++) cout << (G.AddNode()->n=i) << ' ';
1.45 + //cout << '\n';
1.46 +
1.47 + i=0;
1.48 + for(G.GetFirst(n);n.isValid();n++)
1.49 + for(G.GetFirst(m);m.isValid();++m)
1.50 + if(n!=m) G.AddEdge(n,m)->id=++i;
1.51 +
1.52 + cout << "Number of edges: " << i << "\n\n";
1.53 +
1.54 + TestGraph::AllEdgeIterator a;
1.55 + for(G.GetFirst(a);a.isValid();++a)
1.56 + cout << a->id << ":" << a.From()->id << "->" << a.To()->id << " ";
1.57 +
1.58 + cout << "\n\n\n";
1.59 +
1.60 + for(G.GetFirst(n);n.isValid();++n)
1.61 + {
1.62 + cout << n->id << "->";
1.63 + for(G.GetFirst(e,n);e.isValid();++e)
1.64 + cout << e->id << ":" << e.To()->id << ' ';
1.65 + cout << '\n';
1.66 + }
1.67 +
1.68 + cout << "\n\n\n\nB-verzio:\n\n\n";
1.69 +
1.70 + G.Clean();
1.71 +
1.72 + for(i=1;i<=10;i++) G.AddNode()->id=i;
1.73 +
1.74 + i=0;
1.75 + for(n=G.First();n.isValid();n++)
1.76 + for(m=G.First();m.isValid();++m)
1.77 + if(n!=m) G.AddEdge(n,m)->id=++i;
1.78 +
1.79 + ;
1.80 + for(n=G.First();n.isValid();++n)
1.81 + {
1.82 + e=G.First(n);
1.83 + while(e.isValid())
1.84 + if((e->id)%2) G.Delete(e++);
1.85 + else ++e;
1.86 + }
1.87 +
1.88 + for(a=G.First();a.isValid();++a)
1.89 + cout << a->id << ": " << a.From()->id << "->" << a.To()->id << " ";
1.90 +
1.91 + cout << "\n\n\n";
1.92 +
1.93 + for(n=G.First();n.isValid();++n)
1.94 + {
1.95 + cout << n->id << "->";
1.96 + for(e=G.First(n);e.isValid();++e)
1.97 + cout << e->id << ":" << e.To()->id << ' ';
1.98 + cout << '\n';
1.99 + }
1.100 +
1.101 +}