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

Parameterized 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/array.h>
#include <LEDA/core/list.h>

using namespace leda;

int main()
{
  Partition<int> P;
  array<partition_item> A(100);  //stores partition_items of P

  //generate 100 blocks containing one item each
  int i;
  for(i=0; i<100; i++) {
    partition_item p=P.make_block(i);
    A[i]=p;
  }

  //unite all blocks with even number
  for (i=2;i<100;i+=2) P.union_blocks(A[0],A[i]);

  //unite all blocks with odd number and store items in list L
  list<partition_item> L;
  L.append(A[1]);
  for (i=3;i<100;i+=2) {
    P.union_blocks(A[1],A[i]);
    L.append(A[i]);
  }

  std::cout << "Size of block containing last item in L: " 
       << P.size(A[99]) << std::endl;


  if (P.same_block(A[0],A[2])) {
    std::cout << "A[0] and A[2] belong to one block" << std::endl;
  }

  P.split(L);  //turn all items in L to singleton blocks
 
  return 0;
}	  

See also:

Partitions

Node Partition


Manual Entries:

Manual Page Parameterized Partition

LEDA Item Concept




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