Returning multiple things and stuff in recursive functions (?)
Author |
Message |
Insectoid
|
Posted: Fri Nov 13, 2009 1:54 pm Post subject: Returning multiple things and stuff in recursive functions (?) |
|
|
So, one of my assignments compares different searching algorithms, displaying the number of comparisons made and the number of times it has looped/recursed.
My problem is that the way I want to do this is to have my functions completely independent of global variables. My recursive binary search already has 4 parameters and I'd have to add 2 more to record stack depth/comparisons, and return the result AND stack depth AND comparisons. I could use an array/hash for that, but I don't want 6 parameters. I want my functions to be individual programs in their own right, so I'd rather they weren't modified too much. Is there some way to accomplish this?
btw, I'm doing this in Actionscript |
|
|
|
|
|
Sponsor Sponsor
|
|
|
jbking
|
Posted: Fri Nov 13, 2009 4:22 pm Post subject: Re: Returning multiple things and stuff in recursive functions (?) |
|
|
Couldn't you build a class that has 6 members that would be each of those parameters within one data structure? Or is that not the route you wanted to go? |
|
|
|
|
|
Insectoid
|
Posted: Fri Nov 13, 2009 5:23 pm Post subject: RE:Returning multiple things and stuff in recursive functions (?) |
|
|
Well, my searches aren't classes, they're functions.
I use include "filename.as" instead. I guess I could make them into classes though. |
|
|
|
|
|
A.J
|
Posted: Fri Nov 13, 2009 5:39 pm Post subject: RE:Returning multiple things and stuff in recursive functions (?) |
|
|
Questions: Can you hash 2 or more numbers into, possibly, one number?
Answer: Of course you can. One way to hash two numbers, say x and y, is to think of an x-by-y table where the squares in the table are numbered, and you want to read out the number in the square (x, y). That hashes these two numbers into one number. There are other methods to hash numbers. |
|
|
|
|
|
jbking
|
Posted: Thu Nov 19, 2009 2:27 pm Post subject: Re: RE:Returning multiple things and stuff in recursive functions (?) |
|
|
A.J @ Fri Nov 13, 2009 3:39 pm wrote: Questions: Can you hash 2 or more numbers into, possibly, one number?
This may or may not be doable, IMO.
An example where it can be done is mapping elements of the Rational number system into the Natural number system. Rationals are also known as fractions and pairs of integers are one way to interpret them,e.g. a half is the pair (1,2).
An example where it isn't possible would be to map any pair of Real numbers into the Natural number system using a bijective function. "Cardinality of the Continuum" is the proof for anyone thinking, "What the...?" |
|
|
|
|
|
Prabhakar Ragde
|
Posted: Thu Nov 19, 2009 3:29 pm Post subject: RE:Returning multiple things and stuff in recursive functions (?) |
|
|
Hash functions are rarely bijections. They're deliberately trying to map values into a smaller range. |
|
|
|
|
|
|
|