# source:lemon-0.x/demo/hello_world.cc@2195:f47faf6913ab

Last change on this file since 2195:f47faf6913ab was 2195:f47faf6913ab, checked in by Alpar Juttner, 18 years ago

Tutorial improvements by Mark (mqrelly)

File size: 3.1 KB
Line
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19///\ingroup demos
20///\file
21///\brief LEMON style "Hello World!" program
22///
23/// This program is intended to be a "Hello World!" program that shows
24/// the very basic notions of the LEMON library: \ref graphs "graphs" and
26///
27/// \include hello_lemon.cc
28
29#include <iostream>
30#include <lemon/list_graph.h>
31
32using namespace lemon;
33
34typedef ListGraph::Node  Node;
35typedef ListGraph::Edge  Edge;
36
37
38int  main( int argc, char *argv[] )
39{
40  // Declare the graph itself and a NodeMap, witch will store the characters
41  // assigned to the nodes
42  ListGraph  graph;
43  ListGraph::NodeMap<char>  char_map(graph);
44
47  char_map[new_node] = 'H';
48
49  // Store the start node
50  Node  start_node = new_node;
51
52  Node  from_node = new_node;
54  char_map[new_node] = 'e';
55
56  // Here we add the first edge...
58
59  // ... and we add some more nodes and edges to the graph
60  from_node = new_node;
62  char_map[new_node] = 'l';
64
65  from_node = new_node;
67  char_map[new_node] = 'l';
69
70  from_node = new_node;
72  char_map[new_node] = 'o';
74
75  from_node = new_node;
77  char_map[new_node] = ' ';
79
80  from_node = new_node;
82  char_map[new_node] = 'W';
84
85  from_node = new_node;
87  char_map[new_node] = 'o';
89
90  from_node = new_node;
92  char_map[new_node] = 'r';
94
95  from_node = new_node;
97  char_map[new_node] = 'l';
99
100  from_node = new_node;
102  char_map[new_node] = 'd';
104
105  from_node = new_node;
107  char_map[new_node] = '\n';
109
110
111  // iterating
112  Node  current_node = start_node;
113  while( current_node != INVALID )
114  {
115    std::cout << char_map[current_node] << std::flush;
116
117    ListGraph::OutEdgeIt  edge(graph, current_node);
118    if( edge != INVALID )
119      current_node = graph.target( edge );
120    else
121      current_node = INVALID;
122  }
123
124  return 0;
125}
Note: See TracBrowser for help on using the repository browser.