Algorithmic Solutions > LEDA > LEDA Guide > Simple, Basic, and Advanced Data Types > Basic Data Types > Partitions Example

Partitions Example

The following program shows the operations that are supported by partition, essentially union(), same_block(), and split().

#include <LEDA/core/partition.h>
#include <LEDA/core/list.h>

int main()
{
  leda::partition P;
  leda::list<leda::partition_item> L;  //stores partition_items of P

  //generate 100 blocks containing one item each
  for(int i=0; i<100; i++) {
    leda::partition_item p=P.make_block();
    L.append(p);
  }

  std::cout << "Number of blocks: " << P.number_of_blocks() << std::endl;

  //unite all blocks to one big block
  leda::partition_item p;
  forall(p,L) P.union_blocks(p,L.tail());

  std::cout << "Number of blocks: " << P.number_of_blocks() << std::endl;
  std::cout << "Size of block containing last item in L: " 
       << P.size(L.tail()) << std::endl;

  if (P.same_block(L.head(),L.tail())) {
    std::cout << "head and tail of L belong to one block" << std::endl;
  }

  P.split(L);  //turn all items in L to singleton blocks
  std::cout << "Number of blocks: " << P.number_of_blocks() << std::endl;

  return 0;
}	  

See also:

Parameterized Partition

Node Partition


Manual Entries:

Manual Page Partitions

LEDA Item Concept

 

 




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH