31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.2 Two Dimensional Arrays ( array2 )<br />

1. Definition<br />

An instance A of the parameterized data type array2 is a mapping from a set of pairs<br />

I = [a..b] × [c..d], called the index set of A, to the set of variables of data type E, called<br />

the element type of A, for two fixed intervals of integers [a..b] and [c..d]. A(i, j) is called<br />

the element at position (i, j).<br />

#include < <strong>LEDA</strong>/core/array2.h ><br />

2. Creation<br />

array2 A(int a, int b, int c, int d);<br />

array2 A(int n, int m);<br />

creates an instance A of type array2 with index set [a..b]×[c..d].<br />

creates an instance A of type array2 with index set [0..n − 1] ×<br />

[0..m − 1].<br />

3. Operations<br />

E& A(int i, int j) returns A(i, j).<br />

Precondition: a ≤ i ≤ b and c ≤ j ≤ d.<br />

int A.low1( ) returns a.<br />

int A.high1( ) returns b.<br />

int A.low2( ) returns c.<br />

int A.high2( ) returns d.<br />

4. Implementation<br />

Two dimensional arrays are implemented by C++vectors. All operations take time O(1),<br />

the space requirement is O(I ∗ sizeof(E)).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!