Question: Create an abstract class called AR whose objects will be activation records. Actual activation records for function calls will be objects of subclasses of AR.

Create an abstract class called AR whose objects will be activation records. Actual activation records for function calls will be objects of subclasses of AR. Emulation of activation records of the factorial function and the runtime stack can be achieved by the following subclass of AR called ARfact:

class ARfact extends AR { int n; // parameter int t; // temporary var to store the value of fact(n-1) int returnVal; public String toString() { return "ARfact" + " n = " + n + " t = " + t + " returnVal = " + returnVal; } void fact() { if ( n <= 1 ) { returnVal = 1; RuntimeStack.display(); } else { ARfact newARfact = new ARfact(); newARfact.n = n - 1; // pass parameter value RuntimeStack.push(newARfact); newARfact.fact(); // call fact(n-1) t = newARfact.returnVal; // pass return value of fact(n-1) to t RuntimeStack.pop(); returnVal = n * t; // store the value of fact(n) = n*fact(n-1) } } }

i want to create the same method for quick sort as it mention above. can someone help me to change following quicksort method as same Activation Record method as mention above ?

Create an abstract class called AR whose objects will be activation records. Actual activation records for function calls will be objects of subclasses of AR. Emulation of activation records of the quick sort function and the runtime stack can be achieved by converting the following qiuck sort method into activation record

void quickSort(int A[], int p, int r) { if ( p < r ) { int q = partition(A, p, r); quickSort(A, p, q-1); quickSort(A, q+1, r); } } int partition(int A[], int p, int r) { int x = A[r]; int i = p-1; int temp; for ( int j = p; j <= r-1; j++ ) if ( A[j] <= x ) { i++; temp = A[i]; A[i] = A[j]; A[j] = temp; } temp = A[i+1]; A[i+1] = A[r]; A[r] = temp; return i+1; }

:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!