PLEASE HELP ME ANSWER QUESTION JAVA 20. Write a Java function ReverseIntArray. T
ID: 647611 • Letter: P
Question
PLEASE HELP ME ANSWER QUESTION JAVA
20. Write a Java function ReverseIntArray. This function is passed a int[] array parameter, and the function ReverseIntArray will reverse all the elements within the array.
Please using stack to implement this ReverseIntArray(int[] array) and write an additional code fragment to test this function. Include any declarations and initialization statements necessary to test the function.
public static void main(String[] args)
{
/*Write your test program here */
}
public static void ReverseIntArray(int[] array)
{
/*** finish the function here */
} (Points : 10)
Explanation / Answer
Reversing an integer array:
public class reverse
{
public:
int tp;
Stack s=new Stack();
int[] a = new int[];
void rArray(int a[], int st, int ed)
{
if(st >= ed)
System.out.println("cannot compute");
tp = a[st];
a[st] = a[ed];
a[ed] = tp;
s.push(a[st]);
int i,length;
for (i=0; i < length; i++)
{
System.out.println("elements are printed using pop operation");
System.out.println(s.pop(a[i]));
}
};
public static void main(String args[])
{
reverse rev;
int[] arr = new int[] {1, 2, 3, 4, 5};
System.out.println("Reversed array is");
rev.rArray(arr,0,4);
rev.pArray(arr, 5);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.