Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 8th, 2004, 12:01 AM
Infinite Loop Infinite Loop is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 34 Infinite Loop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 35 sec
Reputation Power: 5
BubbleSort Algorithm..Counting Data Moves?

i have a bubblesort function below, but i have a problem.....i need to know the number of "data moves" which "is movement of an element of data from one position in the array to another, to a hold area or from a hold area back to the array."

so far heres the code:

Code:
void bubbleSort (int list [], int last)
{
//	Local Definitions 
	int   current;
	int   walker;
	int   temp;
	bool  sorted;

//	Statements 
	// Each iteration is one sort pass 
	for (current = 0, sorted = false; 
	     current <= last && !sorted;
	     current++)
	   for (walker = last, sorted = true; walker > current; walker--)

	      if (list[walker]  < list[walker - 1])
	         // Any exchange means list is not sorted 
	         {
	          sorted           = false;
	          temp             = list[walker];
	          list[walker]     = list[walker - 1];
	          list[walker - 1] = temp;
	        
			 } 
			 



	return;
}	



so how would i know how to calculate the number of times a data move is made?

Last edited by Infinite Loop : April 8th, 2004 at 12:19 AM.

Reply With Quote
  #2  
Old April 8th, 2004, 12:15 AM
codergeek42's Avatar
codergeek42 codergeek42 is offline
[Insert clever comment here.]
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jul 2003
Location: Anaheim, CA (USA)
Posts: 6,459 codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 39542 Folding Title: Starter FolderFolding Points: 39542 Folding Title: Starter Folder
Time spent in forums: 1 Month 1 Week 6 Days 21 h 42 m 24 sec
Reputation Power: 1231
Send a message via ICQ to codergeek42 Send a message via AIM to codergeek42 Send a message via Yahoo to codergeek42 Send a message via Google Talk to codergeek42
I'm presuimng this is C++. Okay:
Code:
oid bubbleSort (int list [], int last)
{
//	Local Definitions 
	int   current;
	int   walker;
	int   temp;
	int move = 0;
	bool  sorted;
        int numDataMoves = 0;
//	Statements 
	// Each iteration is one sort pass 
	for (current = 0, sorted = false; 
	     current <= last && !sorted;
	     current++)
	   for (walker = last, sorted = true; walker > current; walker--)

	      if (list[walker]  < list[walker - 1])
	         // Any exchange means list is not sorted 
                 // if they need tob be exchanged, increment the numDataMoves counter
	         {
	          sorted           = false;
	          temp             = list[walker];
	          list[walker]     = list[walker - 1];
	          list[walker - 1] = temp;
	          numDataMoves++;
			 } 
			 
			 cout << " \n  |Bubble Sort   |              " << temp << "number of data moves/swaps:" << numDataMoves;  


	return;
}	
Hth!
__________________
~~ Peter ~~
( My Blog: It's exactly like normal nerdiness, but completely different. ) :: ( Supporter of the EFF & FSF ) :: ( I'm a GNU/Linux addict and Free Software Advocate. ) :: ( How to Ask Questions the Smart Way ) :: ( The Fedora Project, sponsored by Red Hat ) :: ( GNOME: The Free Software Desktop Project ) :: ( GnuPG Public Key )

Reply With Quote
  #3  
Old April 8th, 2004, 12:32 AM
Infinite Loop Infinite Loop is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 34 Infinite Loop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 35 sec
Reputation Power: 5
thanks let me give that a try.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > BubbleSort Algorithm..Counting Data Moves?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT