Question: Read the comments in the BagsInterface.java source file. You will be tasked with implementing the resize method (how do you wish to resize the Bags
Read the comments in the BagsInterface.java source file. You will be tasked with implementing the resize method (how do you wish to resize the Bags array? I leave that up to you; you could double the size of the array, resize array one element at a time per call, etc) and also the sort method (I highly recommend using the sort code from our Big O Notation analysis assignment).
Sort function code:
private static void helper(Bags a[], int k, int n) { while ( k*2 + 1 < n ) { int child = 2*k + 1; if ((child + 1 < n) && (a[child] < a[child+1])) child++; if (a[k] < a[child]) { swap( a[child], a[k] ); k = child; } else return; } } public static void sort() { int N = this.num_items; for (int i = N/2; i >= 0; i--) { helper( bag, i, this.num_items); } while (N-1 > 0) { T temp = bag[N-1]; bag[N-1] = bag[0]; bag[0] = temp; helper(bag, 0, N-1); N--; } }
public final class Bag
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
