Pascal Language - Inverting the elements of an array- recursion

December 2016





Here is a recursive procedure that allows the elements to reverse part of a table between the position p and n:

Procedure Invert (Var t : Tab; p, n : Integer);   

Var aux : Real;   
Begin                            
     If p < n Then   
     Begin   
          aux := t[p];   
          t[p] := t[n];   
          t[n] := aux;   
          Inverser (t, p + 1, n - 1);             
     End;   
End;


Thanks to Zouari Lazhar for this tip

Related :

This document entitled « Pascal Language - Inverting the elements of an array- recursion » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.