Search:

Type: Posts; User: Norm

Search: Search took 0.21 seconds.

  1. Re: Keeping track of found objects in array and smallest value

    Create the new array WHEN you know how large it needs to be. The new code I've described would replace this statement:
    valueFound.length = count;

    After the copy was made, valueFound could be...
  2. Re: Keeping track of found objects in array and smallest value

    If you have an array with 10 slots with the first 6 elements containing data
    and create a new array with 6 slots
    and copy the first 6 slots from the first array to the second array, (See the Arrays...
  3. Re: Keeping track of found objects in array and smallest value

    I suggested that you create a NEW array of the desired size.
    Then copy the elements from the old array to the new array. The Arrays class has a method to do that.

    ArrayList is a java class. ...
  4. Re: Keeping track of found objects in array and smallest value

    Use an ArrayList to hold the data and there is no need to resize it.
  5. Re: Keeping track of found objects in array and smallest value

    See post #18
    To change size: define a new array of the desired size and copy the contents of the old array to the new array.
  6. Re: Keeping track of found objects in array and smallest value

    What are you trying to do with this statement:
    valueFound.length = count; // change the size of the array????
  7. Re: Keeping track of found objects in array and smallest value

    That value has the length of the array. You can NOT change the size of an array. You CAN define a new array of the desired size and copy the contents of the old array to the new array.
  8. Re: Keeping track of found objects in array and smallest value

    What was the size of the array where the error happened?
    How did the index for that array get the value: 10?



    The code changes the value of the for loop control variable: k inside the loop....
  9. Re: Keeping track of found objects in array and smallest value

    At line 58 the code used an index with value of 10 in an array that had less than 11 elements in it.
    Check the code to see why the value of the index went past the end of the array.
    Remember that...
  10. Re: Keeping track of found objects in array and smallest value

    Does the code do what you want now?

    You have gone too far with the comments now. Several of them are redundant.
    Put a few lines of comments before a major loop describing its purpose. Most of...
  11. Re: Keeping track of found objects in array and smallest value

    If those comments were in the code, it would make the code easier to understand.

    Did you understand the pseudo code I posted for searching a list for the smallest value?
  12. Re: Keeping track of found objects in array and smallest value

    What are the two loops for? Is this code only for finding the smallest value or is there other stuff mixed in with it?
    BTW That is what comments are for > To describe what the code is supposed to...
  13. Re: Keeping track of found objects in array and smallest value

    Save them in a list or array.


    Search the list for the smallest.
  14. Re: Keeping track of found objects in array and smallest value

    Do you have a question or problem?
  15. Re: Keeping track of found objects in array and smallest value

    An array would work, but it has maintenance problems. An ArrayList is much easier to use.
Results 1 to 15 of 15