Question:
Are complex data structures the same as arrays?
Carebear
2010-06-03 19:32:58 UTC
What would the need be for complex data structures and how are they used? I have read my chapter on arrays but am still having a hard time understanding the design and application as well as the question above. HELP!
Three answers:
Ratchetr
2010-06-03 19:46:50 UTC
An array holds a single data type. You can have an array of ints, or doubles, or strings, or...anything else that is a type.



You can't have an array with some ints, some doubles and a string.



If you want to store 2 ints, 2 doubles and a string as a "package", you use a data structure.



If you happen to have a bunch of those "packages", then you might have an array of those data structures.



Each element in the array is one "package". And it has 2 ints, 2 doubles and a string.
no1home2day
2010-06-04 02:46:47 UTC
An array is like a bunch of mail boxes right next to each other, and each mail box can only hold one letter (snail mail), and all the letters are of the same kind.



A complex data structure is like one mail box that can hold many letters (snail mail) of many different kinds.



The array is set up with a DIM statement that tells the computer exactly how many "mail boxes" will be available.



The data structure is set up in advance exactly what kinds of letters (snail mail) it can hold.



(I keep saying "snail mail" so that you don't confuse "letter" with an actual alphabet letter, such as the letter "B".)



I don't remember how to set up a data structure (My bad. Sorry!)



But to set up the array, you use the DIM statement.



For instance, if you want to be able to hold 30 integers in an array called "Scores", you would type:



DIM Scores(30) as Integer



Score (1) will hold one integer.

Score (2) will hold only one integer.

Score (3) will hold one integer.

Etc.



Each Score(n) is like one of the mailboxes that can hold only one snail mail letter; in THIS case only an integer.



Does that help at all? Good luck.
anonymous
2010-06-04 02:36:58 UTC
You have a file that has a header with 10 records of 9 fields each, and a data area of many records of 3 fields each. You can't represent that in an array, but you can in a struct. (BTW, that's a very rough description of a dbf file.)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...