home *** CD-ROM | disk | FTP | other *** search
- \bigskip
- \bigskip
- {\magonebf 3.2 Two Dimensional Arrays (array2)}
-
- An instance $A$ of the data type $array2$ is a mapping from a set of pairs
- $I = [a..b] \times [c..d]$, called the index set of $A$, to a set of
- variables of a data type $E$, called the element type of $A$, for two fixed
- intervals of integers $[a..b]$ and $[b..c]$. $A(i,j)$ is called the element
- at position $(i,j)$.
-
-
- {\bf 1. Declaration of a two dimensional array type}
-
-
- \decl array2 E
-
- introduces a new data type with name \name\ consisting of all two-dimensional
- arrays with element type $E$.
-
-
-
- \bigskip
- {\bf 2. Creation of a two-dimensional array }
-
-
- \create A (a,b,c,d)
-
- creates an instance \var\ of type \name\ with index set $[a..b]\times [c..d]$.
-
-
- \bigskip
- {\bf 3. Operations on a two-dimensional array A}
- \cleartabs
- \+&\hskip 1.5truecm &\hskip 6truecm &\cr
- \+\opf E\& {int\ i,\ int\ j}
- {returns $A(i,j)$. }
- \+\nop {\precond $a\le i\le b$ and $c\le j\le d$. }
- \smallskip
- \+\op int low1 {}
- {returns $a$}
- \smallskip
- \+\op int high1 {}
- {returns $b$}
- \smallskip
- \+\op int low2 {}
- {returns $c$}
- \smallskip
- \+\op int high2 {}
- {returns $d$}
- \smallskip
-
-
- \bigskip
- {\bf 4. Implementation}
-
- Two dimensional arrays are implemented by \CC vectors. All operations
- take time $O(1)$, the space requirement is $O(|I|)$.
-
-
-