These are some of the simplest recursive functions I think I've ever written...

notfred

Lifer
Feb 12, 2001
38,241
4
0
A couple examples:

public int lowKey(){
return subNodes[0].lowKey();
}

public void print(){
for(int i=0; i < used; i++){
subNodes[ i ].print();
}

And yes they actually work correctly...

I'm not sure if they're harder or easier to understand than traditional recursive functions. This is in java, btw.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
traverses a Btree. The first one find the lowest value along a certain branch, and the second one prints out all the values in the tree.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Wow
rolleye.gif
 

stonecold3169

Platinum Member
Jan 30, 2001
2,060
0
76
hehe, speaking of recursion, anyone wanna take a gander at the most recursive program on earth? behold the mighty powers of Scheme and it's uses in breaking RSA encryption :D (also my hw for this weekend)
 

alareau

Senior member
Sep 3, 2000
566
0
76
Originally posted by: stonecold3169
hehe, speaking of recursion, anyone wanna take a gander at the most recursive program on earth? behold the mighty powers of Scheme and it's uses in breaking RSA encryption :D

oh the horror of scheme, it's brining back my nightmares of when i had to use it :frown:
 

stonecold3169

Platinum Member
Jan 30, 2001
2,060
0
76
Originally posted by: alareau
Originally posted by: stonecold3169
hehe, speaking of recursion, anyone wanna take a gander at the most recursive program on earth? behold the mighty powers of Scheme and it's uses in breaking RSA encryption :D

oh the horror of scheme, it's brining back my nightmares of when i had to use it :frown:

hey man, there is some stuff that you can do in scheme that you can't do in other languages, at least easily. Hell, in c++ it's tricky to get a number 2^1024 digits long, PLUS you need to check if thats prime, where in c++ that turns into a major time consuming ordeal... i's limited in true usage, but for cryptography it rocks
 

Garion

Platinum Member
Apr 23, 2001
2,331
7
81
My favorite recursive program..

main() {
while(1)
fork();
}

(Probably slaughtered the code, haven't written C in years)

Whee! How to take down the school's primary unix server!

- G
 

charrison

Lifer
Oct 13, 1999
17,033
1
81
Originally posted by: stonecold3169
Originally posted by: alareau
Originally posted by: stonecold3169
hehe, speaking of recursion, anyone wanna take a gander at the most recursive program on earth? behold the mighty powers of Scheme and it's uses in breaking RSA encryption :D

oh the horror of scheme, it's brining back my nightmares of when i had to use it :frown:

hey man, there is some stuff that you can do in scheme that you can't do in other languages, at least easily. Hell, in c++ it's tricky to get a number 2^1024 digits long, PLUS you need to check if thats prime, where in c++ that turns into a major time consuming ordeal... i's limited in true usage, but for cryptography it rocks

That is why you get a bigmath library....