#ArrayList disappears when a method is called

5 messages · Page 1 of 1 (latest)

frosty gate
#

I have been implementing an algorithm into Java (Johnson and Trotter) and have found that my ArrayList containing all the numbers i am operating on disappears after a method is called, leading to no items being returned. I will explain the algorithm as best as i can below:

The algorithm i am trying to implement generates all possible shuffles of a collection of numbers by giving them all a direction and specifying any number bigger than the number it is pointing to as "mobile", every pass, the largest "mobile" number is swapped with the number it is pointing to and this generates a unique shuffle, this process continues until no numbers are "mobile", at which point, all combinations are found

The method which "vanishes" my ArrayList of numbers is the one which checks if a number is mobile or not, i have left a comment in the source code to where this method is called, which i have linked below.

Thank you for your help

balmy nymphBOT
#

This post has been reserved for your question.

Hey @frosty gate! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

balmy nymphBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

errant jungle
#

Hello. I have taken a look at your code and saw that you have the following: while (largestCumulativeNumber.get(0) != 0). Before that, you state: largestCumulativeNumber.add(0);. That means that largestCumulativeNumber.get(0) != 0 will always be false and code inside the while loop block will never execute. Maybe, the problem is related to this?