All pastes #769011 Raw Edit

Bubble Sort Algorithm

public c v1 · immutable
·published 2007-11-11 01:24 UTC
rendered paste body
void swap(int iSwap[], int iVal, int iOffset){	//A function to swap two values in an array at index iVal, iVal+iOffset.	//Written expressely for bSorta	int iIntermediate;	iIntermediate = iSwap[iVal];	iSwap[iVal] = iSwap[iVal+iOffset];	iSwap[iVal+iOffset] = iIntermediate;}void bSortd(int iSortArray[], int iSize){	//Bubble Sort Algorithm in Descending (highest to lowest) order, where the lowest index number = highest value.		//Initialize vars	int isDone;		//'Finished' boolean	int iCounter;	//Counter			//Begin sorting loop	do 	{		isDone		= TRUE;						//We are done unless we find an unsorted value		iCounter	= 0;						//Back at start of array		while(iCounter < iSize)		{			if(iSortArray[iCounter] < iSortArray[iCounter + 1])			{				swap(iSortArray, iCounter, 1); 	//Swap the two values at iCounter, iCounter+1				isDone = FALSE;					//We have found an unsorted value - are we done? Obviously not.			}			iCounter++;							//Increment iCounter		}	} while (isDone==FALSE);}