Question: //This recursive function return the array by reversing values between Starting Index and Ending Index //Would like to transform recursive function to forwards recursive function
//This recursive function return the array by reversing values between Starting Index and Ending Index
//Would like to transform recursive function to forwards recursive function
import java.util.Arrays; import java.util.Scanner;
public class ReversalArray
{ private static Scanner tool; public static void Reversal(int [] data, int low , int high) { if (low < high) { int temp= data[low]; //burada data[low] la data[high] in contentlerini temp sayesinde swap ediyoruz data[low]= data[high]; data[high]= temp; Reversal(data, (low+1), (high-1)); } } public static void main (String[] args) { System.out.println("Please enter starting index : "); tool = new Scanner(System.in); int StartingIndex= tool.nextInt(); System.out.println("Please enter ending index : "); int EndingIndex= tool.nextInt(); //EndingIndex= 5; int [] data= {4,3,6,8,9,5}; Reversal(data, StartingIndex, EndingIndex); System.out.println("This is the array in reverse"); System.out.println(Arrays.toString(data)); tool.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
