Results 1 to 1 of 1
- 03-12-2009, 04:07 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 36
- Rep Power
- 0
Keeping track of Copies + Comparisons in Sort Methods
I'm trying to figure out the correct placement of "copies" and "comparison" integers I have declared. Will someone please help?
After sorting 100,000 floats from 0-99 I have come up with the following output:
The number of comparisions made using insertion sort: 4
The number copies made using insertion sort:9999
This is obviously incorrect, can someone show me/help me understand the correct location?
Java Code:public void insertionSort() { int comps = 0; int copies = 0; int in, out; for (out = 1; out < nElems; out++) // out is dividing line { float temp = theArray[out]; // remove marked item in = out; // start shifts at out while (in > 0 && theArray[in - 1] >= temp) // until one is smaller, { comps++; theArray[in] = theArray[in - 1]; // shift item to right --in; // go left one position } theArray[in] = temp; // insert marked item copies++; } // end for
Similar Threads
-
Trace and track hp number on jsp
By angelicsign in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-16-2008, 06:39 AM -
Need some help bad, at wits end validating this form and keeping script.
By bastardpete in forum New To JavaReplies: 1Last Post: 08-27-2008, 04:27 AM -
POI for delete excel record with keeping the existing macros
By Jay in forum Advanced JavaReplies: 0Last Post: 07-31-2008, 10:44 AM -
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM -
Track download
By nilesh.malode in forum Advanced JavaReplies: 1Last Post: 07-13-2007, 09:44 PM
Bookmarks