An example of JavaScript recursion to implement reverse array string, javascript Recursion
<! DOCTYPE html>
Use JavaScript to sort string arrays.
/**
* Sort
@ Param opt: String Array to be sorted
*/
Function sortString (opt ){
If (! Opt) return;
Var result = [], nresult = [],
TempNum = 0, tempTNum = 0, nk = 0;
For (var I = 0; I <opt. length; I ++ ){
Var syt = opt [I], num = 0;
For (var j = 0; j <syt. length; j ++ ){
Var k = 0, tempnum = 0,
Str = syt. substr (j, j + 1 );
While (syt. indexOf (str, k )! =-1 ){
Tempnum ++;
K = syt. indexOf (str, k) + 1;
}
If (tempnum> num ){
Num = tempnum
}
}
Result [result. length] = num;
}
For (var n = 0; n <result. length; n ++ ){
TempTNum = result [n];
For (var m = 0; m <result. length; m ++ ){
If (tempTNum <result [m]) {
TempTNum = result [m];
Nk = m;
}
}
Nresult [nresult. length] = opt [nk];
Result [nk] =-1;
}
Return nresult;
}
In fact, this is an algorithm, but the above Code does not take efficiency into account, but only achieves the effect
C ++ compiles a recursive function to output a string in reverse order.
Char str [] = "backward output ";
Void rec_print (char * str)
{
If (0 = str | 0 = str_len (str) return;
Printf ("% c", str [strlen (str)-1]);
Str [strlen (str)-1] = 0;
Rec_print (str );
}
Void rec_print_no_pointer (std:; string & str)
{
If (! Str. size () return;
Std: cout <str. substr (str. size ()-1, 1 );
Str = str. substr (0, str. size ()-1 );
Rec_print_no_pointer (str );
}