Move the first half of cards into firstHalf // This may or may not be done in one line of code Move the remaining elements in cards into secondHalf // This may or may not be done in one line of code While there are elements in firstHalf Remove the element at the start of firstHalf and add it to cards Remove the element at the start of secondHalf and add it to cards EndWhile If secondHalf has any elements remaining Remove the element at the start of secondHalf and add it to cards EndIf
this is the error I am getting. Why is my list growing if I am removing?Should I be doing something like this inside my first for loop
firstHalf.add(cards.remove(0));
cards= firstHalf.add(cards.remove(0));
this is the error I am getting
shuffle() should not change the number of elements in cards. cards had contained a complete 52 card deck, but now has size: 71 expected:<52> but was:<71>
public void shuffle(ListGenerator gen) {
List<PlayingCard> firstHalf = gen.createNewList();
List<PlayingCard> secondHalf = gen.createNewList();
for (int i = 0; i <= (cards.size() / 2); i++) {
firstHalf.add(cards.remove(0));
}
secondHalf.addAll(cards);
while (firstHalf.isEmpty() == false) {
cards.add(firstHalf.remove(0));
cards.add(secondHalf.remove(0));
}
if (secondHalf.isEmpty() == false) {
cards.add(secondHalf.remove(0));
}
}*