Pascal : inverting a string with recursion -


i'm trying learn recursion in pascal, , have code invert string recursion :

function invert (ch:string) : string;      begin      if ch=''      invert:=''      else       invert:=copy(ch,length(ch),1)+invert(copy(ch,1,length(ch)-1));     end; 

can explain me what's going on here step step. thank you.

if string empty, inversion empty string; otherwise, inversion last character followed inversion of (the string minus last character).

fortunately, have function can invert string: invert.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -