Implement changeArrayLength(int m) – void method; public class Course { public String code; public int capacity; public SLinkedList[] studentTable; public int size; public SLinkedList waitlist; public Course(String code) { this.code = code; this.studentTable = new SLinkedList[10]; this.size = 0; this.waitlist = new SLinkedList(); this.capacity = 10; } public Course(String code, int capacity) { this.code = code; this.studentTable = new SLinkedList[capacity]; this.size = 0; this.waitlist = new SLinkedList<>(); this.capacity = capacity; } public void changeArrayLength(int m) { // insert your solution here } This method creates a new student table for this course; this new table has the given length m; the method moves all registered students to this table, as described in more detail below. Note that this method itself does not move the waitlisted students. This method creates a new array of SLinkedList, moves all the registered students into these linked lists, and changes this course’s studentTable field so it references this new table instead. Each student in the current table will be moved to the new table. This will require in most cases that the student is moved to a different array slot index. The slot index for the SLinkedList that they are moved to is id % m, where m is the new length of the array (the parameter of the method). The motivation for increasing the capacity of the array is that it keeps the average lengths of the linkedlists below 1, which tends to mean a fast traversal of each linked list. ** I already have public class Student and public SLinkedList defined **
Implement changeArrayLength(int m) – void method;
public class Course {
public String code;
public int capacity;
public SLinkedList<Student>[] studentTable;
public int size;
public SLinkedList<Student> waitlist;
public Course(String code) {
this.code = code;
this.studentTable = new SLinkedList[10];
this.size = 0;
this.waitlist = new SLinkedList<Student>();
this.capacity = 10;
}
public Course(String code, int capacity) {
this.code = code;
this.studentTable = new SLinkedList[capacity];
this.size = 0;
this.waitlist = new SLinkedList<>();
this.capacity = capacity;
}
public void changeArrayLength(int m) {
// insert your solution here
}
This method creates a new student table for this course; this new table has the given length m; the method moves all registered students to this table, as described in more detail below. Note that this method itself does not move the waitlisted students. This method creates a new array of SLinkedList, moves all the registered students into these linked lists, and changes this course’s studentTable field so it references this new table instead. Each student in the current table will be moved to the new table. This will require in most cases that the student is moved to a different array slot index. The slot index for the SLinkedList that they are moved to is id % m, where m is the new length of the array (the parameter of the method). The motivation for increasing the capacity of the array is that it keeps the average lengths of the linkedlists below 1, which tends to mean a fast traversal of each linked list.
** I already have public class Student and public SLinkedList defined **
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images