Java and Data structure It is almost Halloween time Three ki
Java and Data structure
It is almost Halloween time. Three kids: Larry, Curly and Moe decide to go trick or treating together dressed as an array, Array List and Linked List respectively. They go to a number of houses and get a piece of candy at each house. When they are done, they talk about their experience and realize that the candy from one of the houses was spoiled. They all go and grab that piece, and throw it away. Then they sit and eat the most recent half of candy that they just collected. Implement this situation in a method. Create an array, Array List and Linked List. The number of houses, and the specific house that had bad candy are input variables. Candy is an object that you can assume is declared and defined. You should \"visit\" each house and add a piece of candy to your list at each \"visit.\" After you have doled out all the candy, remove the piece of candy at the specified \"house\" (location). Then remove the last half of the candy. Assume you have a large number of houses (for instance 100,000), comment on the performance of each of the trick or treaters.
Solution
public static void trickOrTreat(int numberOfHouses, int badCandyIndex){ // initialize the variables Object[] array = new Object[numberOfHouses]; int arrLength = numberOfHouses; // need to hold array length to represent number of candy left ArrayList