Ashref Ashref - 1 year ago 128
Pascal Question

Pascal : inverting a string with recursion

I'm trying to learn recursion in pascal, and i have this code to invert a string with recursion :

Function Invert (ch:string) : string;

if ch='' then


Can anyone explain to me what's going on here step by step.
Thank you.

Answer Source

If the string is empty, its inversion is just the empty string; otherwise, the inversion is the last character followed by the inversion of (the string minus its last character).

Fortunately, you have a function that can invert a string: Invert.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download