# HG changeset patch # User athos # Date 1079628607 0 # Node ID b9158a014fe8833956ed7ab5901de96c912230b2 # Parent f40bb16b0405e86fbfb820596498f5ff100cc3fe Alp?r javaslat?ra k?sz?tettem egy strukt?r?t 2 dimenzi?s vektorok (s?kvektorok) t?rol?s?ra. Olyasmiket tud, amiket s?kvektorokt?l szeretn?nk. A neve: xy, a hasonl? nevu .h file-ban tal?lhat?. diff -r f40bb16b0405 -r b9158a014fe8 src/work/athos/makefile --- a/src/work/athos/makefile Thu Mar 18 12:07:37 2004 +0000 +++ b/src/work/athos/makefile Thu Mar 18 16:50:07 2004 +0000 @@ -1,7 +1,7 @@ CXXFLAGS = -Wall -ansi -g CXX = g++-3.0 -pf_demo: pf_demo.cc ../marci_graph_traits.hh ../marci_list_graph.hh ../marci_property_vector.hh preflow_push.hh ../reverse_bfs.hh +pf_demo: pf_demo.cc ../marci_graph_traits.hh ../list_graph.hh ../marci_property_vector.hh preflow_push.hh reverse_bfs.hh $(CXX) $(CXXFLAGS) -I. -I.. pf_demo.cc -o pf_demo diff -r f40bb16b0405 -r b9158a014fe8 src/work/athos/pf_demo.cc --- a/src/work/athos/pf_demo.cc Thu Mar 18 12:07:37 2004 +0000 +++ b/src/work/athos/pf_demo.cc Thu Mar 18 16:50:07 2004 +0000 @@ -23,9 +23,11 @@ typedef ListGraph::InEdgeIt InEdgeIt; typedef ListGraph::SymEdgeIt SymEdgeIt; */ - + ListGraph flowG; + + /* //Marci példája - ListGraph flowG; + NodeIt s=flowG.addNode(); NodeIt v1=flowG.addNode(); @@ -58,62 +60,42 @@ cap.set(v4_v3, 7); cap.set(v3_t, 20); cap.set(v4_t, 4); + */ + //Ahuja könyv példája + NodeIt s=flowG.addNode(); + NodeIt v2=flowG.addNode(); + NodeIt v3=flowG.addNode(); + NodeIt v4=flowG.addNode(); + NodeIt v5=flowG.addNode(); + NodeIt t=flowG.addNode(); - - - - /* - //Ahuja könyv példája - node_iterator s=flow_test.add_node(); - NodeIt v2=flow_test.add_node(); - NodeIt v3=flow_test.add_node(); - NodeIt v4=flow_test.add_node(); - NodeIt v5=flow_test.add_node(); - NodeIt t=flow_test.add_node(); - - node_property_vector node_name(flow_test); - node_name.put(s, "s"); - node_name.put(v2, "v2"); - node_name.put(v3, "v3"); - node_name.put(v4, "v4"); - node_name.put(v5, "v5"); - node_name.put(t, "t"); - - - edge_iterator s_v2=flow_test.add_edge(s, v2); - edge_iterator s_v3=flow_test.add_edge(s, v3); - - edge_iterator v2_v4=flow_test.add_edge(v2, v4); - edge_iterator v2_v5=flow_test.add_edge(v2, v5); - - edge_iterator v3_v5=flow_test.add_edge(v3, v5); - - edge_iterator v4_t=flow_test.add_edge(v4, t); - edge_iterator v5_t=flow_test.add_edge(v5, t); + EdgeIt s_v2=flowG.addEdge(s, v2); + EdgeIt s_v3=flowG.addEdge(s, v3); + EdgeIt v2_v4=flowG.addEdge(v2, v4); + EdgeIt v2_v5=flowG.addEdge(v2, v5); + EdgeIt v3_v5=flowG.addEdge(v3, v5); + EdgeIt v4_t=flowG.addEdge(v4, t); + EdgeIt v5_t=flowG.addEdge(v5, t); //Kis modositas - edge_iterator v2_s=flow_test.add_edge(v2, s); + //edge_iterator v2_s=flowG.add_edge(v2, s); - edge_property_vector cap(flow_test); - cap.put(s_v2, 10); - cap.put(s_v3, 10); - cap.put(v2_v4, 5); - cap.put(v2_v5, 8); - cap.put(v3_v5, 5); - cap.put(v4_t, 8); - cap.put(v5_t, 8); + ListGraph::EdgeMap cap(flowG); + + cap.set(s_v2, 10); + cap.set(s_v3, 10); + cap.set(v2_v4, 5); + cap.set(v2_v5, 8); + cap.set(v3_v5, 5); + cap.set(v4_t, 8); + cap.set(v5_t, 8); //Kis modositas - cap.put(v2_s, 100); - - //Kis modositas - //edge_iterator t_s=flow_test.add_edge(t, s); - //cap.put(t_s, 20); - - */ + //cap.put(v2_s, 100); + diff -r f40bb16b0405 -r b9158a014fe8 src/work/athos/xy/xy.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/athos/xy/xy.cc Thu Mar 18 16:50:07 2004 +0000 @@ -0,0 +1,26 @@ +#include +#include +using namespace std; +int main() +{ + cout << "Kerek sok sikvektorokat." << endl; + + xy osszeg; + xy z; + + vector< xy > v; + + while(cin >> z) { + v.push_back(z); + osszeg += z; + cout << "Az összeg aktualisan: " << osszeg << endl; + } + + + + cout << "A kovetkezo szamokat szoroztam ossze:" << endl; + for(unsigned int i=0; i + +using namespace std; +template +class xy { + T _x,_y; + +public: + + ///Default constructor: both coordinates become 0 + xy() { _x=_y=0; } + + ///Constructing from coordinates + xy(T a, T b) { _x=a; _y=b; } + + ///Gives back the x coordinate + T x(){ + return _x; + }; + + ///Gives back the y coordinate + T y(){ + return _y; + }; + + ///Gives back the square of the norm of the vector + T normSquare(){ + return _x*_x+_y*_y; + }; + + ///Increments the left hand side by u + xy& operator +=(const xy& u){ + _x += u._x; + _y += u._y; + return *this; + }; + + ///Decrements the left hand side by u + xy& operator -=(const xy& u){ + _x -= u._x; + _y -= u._y; + return *this; + }; + + ///Multiplying the left hand side with a scalar + xy& operator *=(const T &u){ + _x *= u; + _y *= u; + return *this; + }; + + ///Returns the scalar product of two vectors + T operator *(const xy& u){ + return _x*u._x+_y*u._y; + }; + + ///Returns the sum of two vectors + xy operator+(const xy &u) const { + xy b=*this; + return b+=u; + }; + + ///Returns the difference of two vectors + xy operator-(const xy &u) const { + xy b=*this; + return b-=u; + }; + + ///Returns a vector multiplied by a scalar + xy operator*(const T &u) const { + xy b=*this; + return b*=u; + }; + + ///Testing equality + bool operator==(const xy &u){ + return (_x==u._x) && (_y==u._y); + }; + + ///Testing inequality + bool operator!=(xy u){ + return (_x!=u._x) || (_y!=u._y); + }; + +}; +///Reading a plainvector from a stream +template +inline +istream& operator>>(istream &is, xy &z) +{ + ///This is not the best solution here: I didn't know how to solve this with friend functions + T a,b; + is >> a >> b; + xy buf(a,b); + z=buf; + return is; +} + +///Outputting a plainvector to a stream +template +inline +ostream& operator<<(ostream &os, xy z) +{ + os << "(" << z.x() << ", " << z.y() << ")"; + return os; +} + + + +#endif //HUGO_XY_H