Is this possible, Its just something im trying to do for fun using the recursion technique but thus far it has come to no avail.
Keep in mind this is for Java so does anyone have any hints that i should use, the base structure of the method is as follows:
I was thinking of turning the string into a character array and manipulating from there but i dont see how that could be done recursively, so once again any help would be well appreciated.
Keep in mind this is for Java so does anyone have any hints that i should use, the base structure of the method is as follows:
//a is the string you want reversed and b is the index into the string thus far
//(or it could be the last character of the string) right now i dont know how to put it.
public static String rString(String a,int b) {
}
I was thinking of turning the string into a character array and manipulating from there but i dont see how that could be done recursively, so once again any help would be well appreciated.
If you absolutly must do it recursivly, this is a way:
(This is just a nice pseudo language)
(This is just a nice pseudo language)
string rString(string str)
{
if(str.size() == 1)
return str;
else
return rString(str[1 .. str.size()-1]) + str[0]; //Remove the first character, call itself, put the character back at the end.
}
* edit edit *
my fault, you were right for the most part here is my working method, i had to just read the book I have
here for the right function and it jumped right out at me, "substring" =). Heres the code incase anyone
would ever want to use it.
my fault, you were right for the most part here is my working method, i had to just read the book I have
here for the right function and it jumped right out at me, "substring" =). Heres the code incase anyone
would ever want to use it.
public static String rString(String a,int b) {
if(b == 0) {
return a;
}
else {
return rString(a.substring(1,a.length()),b-1) + a.charAt(0);
}
}
rString PROC a:PTR, b:DWORD
mov edx,b
mov eax,a
jmp _0
_1: mov cl,[eax]
mov [eax+edx+1],cl
inc eax
_0: dec edx
jns _1
ret
rString ENDP
rString PROC a:PTR, b:DWORD
jmp _0
_1: mov cl,[eax]
add eax,b
inc a
mov [eax+1],cl
invoke rString,a,b
_0: dec b
mov eax,a
jns _1
ret
rString ENDP
Lol. Thanks Bit, I already know the asm way to do it, its just with HLLs i seem to lack ;p