Skip to main content
added 51 characters in body
Source Link
SylvainD
  • 29.8k
  • 1
  • 49
  • 93

It looks ok to me.

As a few comments in a random order:

  • I guess I don't have to tell you that writing a non-recursive function for this is quite straightforward.
  • You could give tmp its final value as you define it : char tmp = a[i];.
  • You could make it a tail call recursion by doing reverse(a, i+1, j-1) at the end.
  • It might be a good option to define a function reverse taking only the array and the length as an argument and calling the one you've just posted here. YouIf you were to use this function in a C++ program, you could do this with a single function definition if you use default parameter (i is 0 by default). The main drawback is that you have to give the parameter a somewhat awkward order.

It looks ok to me.

As a few comments in a random order:

  • I guess I don't have to tell you that writing a non-recursive function for this is quite straightforward.
  • You could give tmp its final value as you define it : char tmp = a[i];.
  • You could make it a tail call recursion by doing reverse(a, i+1, j-1) at the end.
  • It might be a good option to define a function reverse taking only the array and the length as an argument and calling the one you've just posted here. You could do this with a single function definition if you use default parameter (i is 0 by default). The main drawback is that you have to give the parameter a somewhat awkward order.

It looks ok to me.

As a few comments in a random order:

  • I guess I don't have to tell you that writing a non-recursive function for this is quite straightforward.
  • You could give tmp its final value as you define it : char tmp = a[i];.
  • You could make it a tail call recursion by doing reverse(a, i+1, j-1) at the end.
  • It might be a good option to define a function reverse taking only the array and the length as an argument and calling the one you've just posted here. If you were to use this function in a C++ program, you could do this with a single function definition if you use default parameter (i is 0 by default). The main drawback is that you have to give the parameter a somewhat awkward order.
Source Link
SylvainD
  • 29.8k
  • 1
  • 49
  • 93

It looks ok to me.

As a few comments in a random order:

  • I guess I don't have to tell you that writing a non-recursive function for this is quite straightforward.
  • You could give tmp its final value as you define it : char tmp = a[i];.
  • You could make it a tail call recursion by doing reverse(a, i+1, j-1) at the end.
  • It might be a good option to define a function reverse taking only the array and the length as an argument and calling the one you've just posted here. You could do this with a single function definition if you use default parameter (i is 0 by default). The main drawback is that you have to give the parameter a somewhat awkward order.