Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2009, 05:07 AM
Member
 
Join Date: Jan 2008
Posts: 36
Rep Power: 0
VinceGuad is on a distinguished road
Default 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?

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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trace and track hp number on jsp angelicsign JavaServer Pages (JSP) and JSTL 0 12-16-2008 07:39 AM
Need some help bad, at wits end validating this form and keeping script. bastardpete New To Java 1 08-27-2008 05:27 AM
POI for delete excel record with keeping the existing macros Jay Advanced Java 0 07-31-2008 11:44 AM
How to sort a list using Bubble sort algorithm Java Tip Algorithms 3 04-29-2008 09:04 PM
Track download nilesh.malode Advanced Java 1 07-13-2007 10:44 PM


All times are GMT +2. The time now is 02:59 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org