Saturday, January 29, 2022

Display array in reverse


public class DisplayArrayInReverse {
public static void main(String[] args) {
int[] arr = new int[]{1, 2, 3, 4, 5, 6};

reverse(arr, 0);
}

private static void reverse(int[] arr, int idx) {
// base case
if (idx == arr.length)
return;

// faith
reverse(arr, idx + 1);

// post order
System.out.println(arr[idx]);
}
}

No comments:

Post a Comment

Diagonal Traversal

 eg.  1       2       3       4 5      6       7       8 9    10    11     12 13  14   15    16 Output: 1 6 11 16 2 7 12 3 8 4  Approach:...