Difference between revisions of "Searching Arrays"

From CompSciWiki
Jump to: navigation, search
(Parallel Array Creation)
Line 5: Line 5:
 
Parallel arrays should be used wherever you want to make a complex structure of similar or related data, but do not have the means.
 
Parallel arrays should be used wherever you want to make a complex structure of similar or related data, but do not have the means.
  
==Parallel Array Creation==
+
==Selection Searching==
  
 
Parallel arrays should be used whenever you need to create a list of items, but all the information you need to store will not fit into a single [[Primitive Data Type]].  
 
Parallel arrays should be used whenever you need to create a list of items, but all the information you need to store will not fit into a single [[Primitive Data Type]].  

Revision as of 11:23, 27 November 2007

COMP 1010 Home > Parallel Arrays


Introduction

Parallel arrays are a predecesor of object arrays, which you will not be learning.(Placeholder)

   

{{{Body}}}

Parallel arrays are an advanced use of arrays. Creation and use is fairly simple, and a natural step from creating and using simple arrays.

Parallel arrays should be used wherever you want to make a complex structure of similar or related data, but do not have the means.

Selection Searching

Parallel arrays should be used whenever you need to create a list of items, but all the information you need to store will not fit into a single Primitive Data Type. For example, you need to to keep a list of people's names and addresses. A single array of Strings seperating the addresses from names with a comma might not practical, and difficult to implement. Using one array for names, and another array of equal size for addresses would be easier and more practical.

    
   String []names = new String[numberOfPeople];
   String []addresses = new String[numberOfPeople];

As you can see, setting up a set of parallel arrays is simply as easy as simply declaring two different arrays. Ensure that the arrays you wish to use in parallel are are created using the same length.

COMP 1010 Home > Parallel Arrays


Introduction

Parallel arrays are a predecesor of object arrays, which you will not be learning.(Placeholder)

   

{{{Body}}}

Parallel arrays are an advanced use of arrays. Creation and use is fairly simple, and a natural step from creating and using simple arrays.

Parallel arrays should be used wherever you want to make a complex structure of similar or related data, but do not have the means.

Parallel Array Creation

Parallel arrays should be used whenever you need to create a list of items, but all the information you need to store will not fit into a single Primitive Data Type. For example, you need to to keep a list of people's names and addresses. A single array of Strings seperating the addresses from names with a comma might not practical, and difficult to implement. Using one array for names, and another array of equal size for addresses would be easier and more practical.

    
   String []names = new String[numberOfPeople];
   String []addresses = new String[numberOfPeople];

As you can see, setting up a set of parallel arrays is simply as easy as simply declaring two different arrays. Ensure that the arrays you wish to use in parallel are are created using the same length.