This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var input = [1, 2, 3, 4, 5]; | |
| var output = []; | |
| for(var itr=input.length;itr>=0;itr--){ | |
| output.push(input[itr-1]); | |
| } | |
| console.log(output); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nums = [1, 2, 3, 4, 5] | |
| total_nums = len(nums) | |
| for itr in range(total_nums//2): | |
| temp = nums[itr] | |
| nums[itr] = nums[total_nums-itr-1] | |
| nums[total_nums-itr-1] = temp | |
| print(nums) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ReverseNum{ | |
| public static void main(String []args){ | |
| int arr[] = {1, 2, 3, 4, 5, 6}; | |
| for (int itr=0; itr<arr.length/2 ;itr++){ | |
| int temp = arr[itr]; | |
| arr[itr] = arr[arr.length-1-itr] ; | |
| arr[arr.length-1-itr] = temp; | |
| } | |
| for(int itr=0; itr<6; itr++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = [1, 3, 4, 5, 6]; | |
| for (var itr=0; itr< arr.length/2 ; itr++){ | |
| var temp = arr[itr]; | |
| arr[itr] = arr[arr.length-1-itr]; | |
| arr[arr.length-1-itr] = temp; | |
| } | |
| console.log(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def reverse_array(arr, start, end): | |
| if start >= end: | |
| return | |
| arr[start], arr[end] = arr[end], arr[start] | |
| reverse_array(arr, start+1, end-1) | |
| nums = [1, 2, 3, 4, 5] | |
| total_nums = len(nums) | |
| reverse_array(arr=nums, start=0, end=len(nums)-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ReverseNum{ | |
| static void rvereseArray(int arr[], int start, int end) | |
| { | |
| int temp; | |
| if (start >= end) | |
| return; | |
| temp = arr[start]; | |
| arr[start] = arr[end]; | |
| arr[end] = temp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function reverse_array(arr, start, end){ | |
| if (start >= end){ | |
| return | |
| } | |
| var temp = arr[start]; | |
| arr[start] = arr[end]; | |
| arr[end] = temp; | |
| reverse_array(arr, start+1, end-1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| arr = [1, 2, 3, 4, 5] | |
| arr.reverse() | |
| print(arr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Main { | |
| /*function reverses the elements of the array*/ | |
| static void reverse(Integer myArray[]) | |
| { | |
| Collections.reverse(Arrays.asList(myArray)); | |
| System.out.println("Reversed Array:" + Arrays.asList(myArray)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = [1, 2, 3, 4, 5]; | |
| arr.reverse() | |
| console.log(arr) |