Reversing an array In place

后端 未结 11 784
温柔的废话
温柔的废话 2020-12-21 04:20

Okay so I\'ve tried to print and Array and then reverse is using another array But I\'m trying to create a For Loop that will take an array and reverse all of the elements i

11条回答
  •  醉梦人生
    2020-12-21 05:02

    For starters, instead of this:

    for (i = a[len] -1; i >= 0, --i;) {
    

    you want this:

    for (i = len-1; i >= 0, --i;) {
    

    but you also only want to go half-way through the array, so it would be

    for (i = len-1; i > j, --i;) {
    

提交回复
热议问题