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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started