This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I am writing a method for a CS assignment that is supposed to take in an array of ints and return the array shuffled. I read elsewhere on these boards where someone explained how to do this but with strings. I tried to follow their code making the appropriate changes for ints but I am having a problem.
the code works fine as long as original doesn't contain 0's but if it does then it results in an infinite loop I was wondering how I could maybe modify the code so that it could avoid this
Originally posted by russell lloyd: The code works fine as long as original doesn't contain 0's but if it does then it results in an infinite loop I was wondering how I could maybe modify the code so that it could avoid this
The general problem is that you are using the output array elements to hold two separate pieces of information: a not-set-yet flag, and the new value. To do this, the not-set-flag value has to be a value that won't occur in the input array.
If that isn't possible, the algorithm can't work. (You need an extra data structure for the not-set-yet flags.) If it is possible, you need to pre-initialize the output array with the not-set-yet value. [ September 20, 2005: Message edited by: Kym Thompson ]