Algorithm for setting up an array??? (1 Viewer)

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
Hey,

Does anyone know a good algorithm for setting up an array.. I'm a bit stuck..

Thanks

Chris42
 

B.A.M

New Member
Joined
Oct 28, 2003
Messages
6
Location
Western Sydney - but I'm a north shore girl at hea
When you say setting up and array do you mean declaring it or clearing its contents?

You don't need to declare any variables in an algorithm thoguh it may be good to note the structure such as an array of records just so that the marker knows where you're heading.

For clearing an array you would need to:

BEGIN
i = 1
FOR i to 100
practice(i) = " "
NEXT i
END

i'm pretty sure, if its wrong let me know

it got rid of the indenting but you get the idea
 

Glide

Member
Joined
Oct 13, 2003
Messages
103
Hmm........
So we dont need to declaire any array of records, we can just assume a variable to be one?
 

saves.the.day

Member
Joined
Oct 29, 2003
Messages
233
Location
Castle Hill
Gender
Undisclosed
HSC
2003
For algorithms, I'm sure that your "i" variable should be 0 as the first element in the array is identified by a 0 but yours is good. I dont think it matters how you start actually.

Personally, i like using

Code:
index= 0
array_length = get the length of desired array

WHILE index < array_length
    array(index) = "data"
    index = indext + 1
ENDWHILE
 

Glide

Member
Joined
Oct 13, 2003
Messages
103
0 isnt always be assumed as the first item in the array, visual basic does that by default, which you can change if you type 'option base 1' at the top of your code...

So yeah, no biggie :)


The question is, what if you dont know the boundaires of your array, and your asked to include one :|
 

MrMiK

Member
Joined
Aug 24, 2003
Messages
143
Location
Albion Park
uh.. im not sure about it.. but can you test for values or somthing inthe array and then step back? or like an error..
"if there is no array value at current index, the last array index is the previous." type of thing.
(sorry for being so vague)

also dont know if this is possible since "0" in the middle would screw it up.
 

shkspeare

wants 99uai
Joined
Jun 11, 2003
Messages
174
for dynamic arrays

begin
let i = 0
for i = 0 to max
blah(i) = ____
next
end
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top