comp.lang.ada
 help / color / mirror / Atom feed
From: boaz@usa.pipeline.com(Boaz Chow)
Subject: Re: array of matrices
Date: 1996/05/04
Date: 1996-05-04T00:00:00+00:00	[thread overview]
Message-ID: <4metga$2jo@news2.h1.usa.pipeline.com> (raw)
In-Reply-To: 4mdjbq$df7@newsbf02.news.aol.com


I have figured out the first method. 
 
This is what I have done : 
 
type Matrix_Size is array (1..50, 1..50) of integer; 
type Matrix is record 
    I : integer; 
   J : integer; 
   Info : Matrix_Size; 
end record; 
type test_array is (integer range <>) of Matrix; 
A : test_array(6); 
 
Your second method looks very good.  But how can I retrive the size (or
dimension) of the matrix? 
 
On May 03, 1996 14:30:18 in article <Re: array of matrices>,
'johnherro@aol.com (John Herro)' wrote: 
 
 
>boaz@usa.pipeline.com(Boaz Chow) writes: 
>> type Matrix is array (integer range <>, integer range <>) of integer;  
>> I want to set up a variable for array (1..N) of Matrix;  
>> I know this won't work:  A : array (1..N) of Matrix; 
>You're right.  You can't directly set up an array of an unconstarined 
>type.  There are two things you can do.  One is to allow for the largest 
>possible matrix for every element in the array, and keep track of the 
>number of rows and columns actually used: 
> 
>type Square15 is array(1 .. 15, 1 .. 15) of Integer; 
>type Matrix is 
>record 
>Data    : Square15; 
>Rows    : Integer; 
>Columns : Integer; 
>end record; 
>... 
>A : array(1 .. N) of Matrix; 
>... 
>A(1).Rows    := 5; 
>A(1).Columns := 15; 
>A(2).Rows    := 15; 
>A(2).Columns := 7; 
>... 
> 
>This has the disadvantage of using more memory than you actually need, but

>is perhaps a bit simpler than the second way.  The second way is to 
>declare an array of *pointers*.  Each pointer can point to a different 
>size matrix: 
> 
>type Matrix is array(Integer range <>, Integer range <>) of Integer; 
>type Ptr is access Matrix; 
>... 
>A : array(1 .. N) of Ptr; 
>... 
>A(1) := new Matrix(1 .. 5, 1 .. 15); 
>A(2) := new Matrix(1 .. 15, 1 .. 7); 
>... 
> 
>I hope this helps. 
>- John Herro 
>Software Innovations Technology 
>http://members.aol.com/AdaTutor 
>ftp://members.aol.com/AdaTutor 
-- 
   ______   Meow 
   \ OO /  _/  
  :(__ =) 
    U \\ 
http://www.sci.csupomona.edu/~cchow




  reply	other threads:[~1996-05-04  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-02  0:00 array of matrices Boaz Chow
1996-05-03  0:00 ` John Herro
1996-05-04  0:00   ` Boaz Chow [this message]
1996-05-04  0:00     ` John Herro
1996-05-10  0:00   ` Ron J Theriault
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox