| Example Node ArraysThe following program shows how a  
#include <LEDA/graph/graph.h>
#include <LEDA/graph/node_array.h>
using namespace leda;
int main()
{
  graph G;
  node v1=G.new_node();
  node v2=G.new_node();
  node v3=G.new_node();
  
  node_array<int> A(G,1);  //define node array A for G
                            //and assign 1 to every node
  std::cout << A[v1] << " " << A[v2] << " " << A[v3] << std::endl;
  int i=0;
  node v;
  
  forall_nodes(v,G) {
    A[v]=i++; //assign new values
  }
  std::cout << A[v1] << " " << A[v2] << " " << A[v3] << std::endl;
  //if new nodes are generated for G, we need to make A
  //valid for the new nodes
  node v4=G.new_node();
  A.init(G);
  
  std::cout << A[v1] << " " << A[v2] << " " << A[v3] << " " << A[v4] << std::endl;
  //outputs "1 1 1 1"
 
  return 0;
}   | See also:Associate Information with Graphs Manual Entries: |