Java, recursively reverse an array

后端 未结 13 1094
悲&欢浪女
悲&欢浪女 2020-12-17 16:44

I haven\'t found anything with the specific needs of my function to do this, yes, it is for homework.

So I have:

public void reverseArray(int[] x) {
         


        
13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 17:17

    psuedo code

    function revarray(a[1...n])
      if a.length == 1 or a.length == 0
        do nothing 
      # return a
      else
         swap a[1] and a[n]
         revarray(a[2...n-1])
      # return a (The function will not return anything but the contents of a are changed)
    

提交回复
热议问题