doc/getstart.dox
changeset 1520 c2c76e4598f6
parent 1519 17e367a93cbb
child 1528 1aa71600000c
equal deleted inserted replaced
5:9fe7a9218ec0 6:5c3d4d2ef915
   104 the \c cofugure to install the library in non-default location.
   104 the \c cofugure to install the library in non-default location.
   105 
   105 
   106 \section helloworld My first program using LEMON
   106 \section helloworld My first program using LEMON
   107 
   107 
   108 If you have installed LEMON on your system you can paste the
   108 If you have installed LEMON on your system you can paste the
   109 following code segment into a file (named e.g. \c hello_lemon.cc)
   109 following code segment into a file (you can find it as \c
   110 to have a first working program that uses library LEMON.
   110 demo/hello_lemon.cc in the LEMON package) to have a first working
       
   111 program that uses library LEMON.
   111 
   112 
   112 \code
   113 \include hello_lemon.cc
   113 #include <iostream>
       
   114 #include <lemon/list_graph.h>
       
   115 
       
   116 int main()
       
   117 {
       
   118   typedef lemon::ListGraph Graph;
       
   119   typedef Graph::EdgeIt EdgeIt;
       
   120   typedef Graph::NodeIt NodeIt;
       
   121   using lemon::INVALID;
       
   122 
       
   123   Graph g;
       
   124   
       
   125   for (int i = 0; i < 3; i++)
       
   126     g.addNode();
       
   127   
       
   128   for (NodeIt i(g); i!=INVALID; ++i)
       
   129     for (NodeIt j(g); j!=INVALID; ++j)
       
   130       if (i != j) g.addEdge(i, j);
       
   131 
       
   132   std::cout << "Nodes:";
       
   133   for (NodeIt i(g); i!=INVALID; ++i)
       
   134     std::cout << " " << g.id(i);
       
   135   std::cout << std::endl;
       
   136 
       
   137   std::cout << "Edges:";
       
   138   for (EdgeIt i(g); i!=INVALID; ++i)
       
   139     std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
       
   140   std::cout << std::endl;
       
   141 }
       
   142 \endcode
       
   143 
   114 
   144 First let us briefly explain how this program works.
   115 First let us briefly explain how this program works.
   145 
   116 
   146 ListGraph is one of LEMON's graph classes. It is based on linked lists,
   117 ListGraph is one of LEMON's graph classes. It is based on linked lists,
   147 therefore iterating throuh its edges and nodes is fast.
   118 therefore iterating throuh its edges and nodes is fast.
   157 
   128 
   158 We can also iterate through all edges of the graph very similarly. The 
   129 We can also iterate through all edges of the graph very similarly. The 
   159 \c target and
   130 \c target and
   160 \c source member functions can be used to access the endpoints of an edge.
   131 \c source member functions can be used to access the endpoints of an edge.
   161 
   132 
   162 If you have saved the preceding code into a file named, say, \c
   133 If your installation of LEMON into directory \c /usr/local was
   163 hello_lemon.cc and your installation of LEMON into directory \c
   134 successful then it is very easy to compile this program with the
   164 /usr/local was successful then it is very easy to compile this
   135 following command (the argument <tt>-lemon</tt> tells the compiler
   165 program with the following command (the argument <tt>-lemon</tt>
   136 that we are using the installed library LEMON):
   166 tells the compiler that we are using the installed library LEMON):
       
   167 
   137 
   168 \verbatim
   138 \verbatim
   169 g++ hello_lemon.cc -o hello_lemon -lemon
   139 g++ hello_lemon.cc -o hello_lemon -lemon
   170 \endverbatim
   140 \endverbatim
   171 
   141