[CSC 204] Re: 2 Questions
Andrew J. Pounds
pounds_aj at mercer.edu
Tue Apr 21 19:30:29 EDT 2009
First --- it would probably be a really good idea for you to check out
the second binarySearch method in the Collections class found in the
Java API.
In the first two examples where I am searching for objects willet1 and
willet2 using the nameComparator, the binarySearch method will return
the actual location in the ArrayList where the object that matches my
search is located. When I search for willet5, which is not in the
list, the binarySearch method will return a negative number. The actual
value that is returned can be used to find out where to insert willet5
in the list so that the list remains sorted. This equation is found in
the API. In the program I used to compute the value of the insertion
point and then used the calculated insertion point to place the willet5
object in the list.
Does that clear things up?
Each time I want to put a new object in the list that doesn't exist in
the list, I have to calculate the insertion point based on the value
returned from the binarySearch method.
>
>> Dr.Pounds
>>
>> I am confused about how your binary search method is working within
>> the print statement, I'm not sure of the purpose. Also, you changed
>> the value of the i t times, why was that? I'm also confused about
>> what each portion of the insertion point variable actually does.
>>
>>
>>
>
>
> -- Andrew J. Pounds, Ph.D. (pounds at theochem.mercer.edu) Associate Professor of Chemistry and Computer Science Mercer University, Macon, GA 31207 (478) 301-5627
--
Andrew J. Pounds, Ph.D. (pounds at theochem.mercer.edu)
Associate Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://theochem.mercer.edu/pipermail/csc204/attachments/20090421/27d700a7/attachment.html
More information about the csc204
mailing list