GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Nov-2006, 16:27
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 117
TransformedBG is on a distinguished road

Differencese in Sorts?


Okay im just woking on some basic functions using arrays.

I got my bubble sort to work using:

CPP / C++ / C Code:
/***********************************************************************
	Function: bubbleSort
	Description: Used to sort and array in accending order
***********************************************************************/
void bubbleSort (int list [], int size)
{
	int temp; //used for actuall swapping process

// i = offset of size, i greater than zero, countdown of i;
	for(int i=(size - 1); i >= 0; i--) 
	{
		//j=1, j <= the offset, j+1
		for(int j=1; j <= i; j++)
		{
			//if the offset of j is greater than list of j. 
			if(list[j-1] > list[j])
			{
				temp = list[j-1]; // temp becomes j-1
				list[j-1]=list[j]; // list becomes j-1
				list[j]=temp; // list j becomes j-1
			}
		}
	}
}

I belive that is a bubble sort?

However i have to right a function using selection sort, and im not sure what the difference is between the 2?

Baisically i have this:

SelectionSort
  1. Precondisiont
    • An array of integer exsists
    • the array has a known size
  2. Postconditoin
    • The Values in the array are sorted from least to greatest
  3. return
    • void
  4. Description
    • Function sorts an integer array using a selection sort.
  5. prototype:
    • void selectionSort(int [], int);

Can someone please help me understand the difference?
  #2  
Old 19-Nov-2006, 18:48
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 117
TransformedBG is on a distinguished road

Re: Differencese in Sorts?


can anyone help?
  #3  
Old 19-Nov-2006, 19:21
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: Differencese in Sorts?


Bubble sort swaps any two values that are in the wrong order, in place. Selection sort, on each iteration, goes through and finds the minimum value in the array, and swaps it with the first value in the array. And then in subsequent iterations, it starts looking through array after the values it has already put there. Google and Wikipedia will explain these much better than I can.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bubble Sorts with 2d Arrays y2l C Programming Language 5 14-Apr-2006 13:01
Bubble/Selection sorts the_crazyman C++ Forum 0 25-Jan-2005 08:15

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:51.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.