/*
Date: 022309
Author: Kevin
Desc: Insertion Sort
*/
bool insertionSortR01(int *const array, int iCount)
{
for(int iRight = 1; iRight < iCount; ++iRight)
{
int iKey = array[iRight];
int iLeft = iRight - 1;
while(iLeft >= 0 && array[iLeft] > iKey)
{
array[iLeft + 1] = array[iLeft];
iLeft -= 1;
}
array[iLeft + 1] = iKey;
}
return true;
}
Monday, February 23, 2009
Wednesday, February 18, 2009
Bubble Sort
/*
Date: 021809
Author: Kevin
Desc: Bubble sort
*/
bool BubbleSortR01(int *const array, int iCount)
{
for(int iLeft = 0; iLeft < iCount; ++iLeft)
{
for(int iRight = iLeft + 1; iRight < iCount; ++iRight)
{
if(array[iLeft] > array[iRight])
{
//swap
array[iLeft] = array[iRight] - array[iLeft];
array[iRight] = array[iRight] - array[iLeft];
array[iLeft] += array[iRight];
}
else
{
}
}
}
return true;
}
/*
Date: 021809
Author: Kevin
Desc: Bubble Sort
*/
bool BubbleSortR02(int *const array, unsigned int iCount)
{
for(unsigned iLeft = 0; iLeft < iCount - 1; ++iLeft)
{
for(unsigned iRight = iCount - iLeft - 1; iRight > 0; --iRight)
{
if(array[iRight] < array[iRight - 1])
{
int iTmp = array[iRight];
array[iRight] = array[iRight - 1];
array[iRight - 1] = iTmp;
}
else
{
}
}
}
return true;
}
/*
Date: 021909
Author: Kevin
Desc: Bubble Sort
*/
bool BubbleSortR03(int *const array, unsigned int iCount)
{
//Judge whether iCount is a legal number
if(0 > iCount)
{
return false;
}
else
{
}
//main part
for(unsigned uRoundOne = 0; uRoundOne < iCount - 1; ++uRoundOne)
{
for(unsigned uRoundTwo = iCount - uRoundOne - 1; uRoundTwo > 0; --uRoundTwo)
{
if(array[uRoundTwo] < array[uRoundTwo - 1])
{
int iTmp = array[uRoundTwo];
array[uRoundTwo] = array[uRoundTwo - 1];
array[uRoundTwo - 1] = iTmp;
}
else
{
}
}
}
return true;
}
Date: 021809
Author: Kevin
Desc: Bubble sort
*/
bool BubbleSortR01(int *const array, int iCount)
{
for(int iLeft = 0; iLeft < iCount; ++iLeft)
{
for(int iRight = iLeft + 1; iRight < iCount; ++iRight)
{
if(array[iLeft] > array[iRight])
{
//swap
array[iLeft] = array[iRight] - array[iLeft];
array[iRight] = array[iRight] - array[iLeft];
array[iLeft] += array[iRight];
}
else
{
}
}
}
return true;
}
/*
Date: 021809
Author: Kevin
Desc: Bubble Sort
*/
bool BubbleSortR02(int *const array, unsigned int iCount)
{
for(unsigned iLeft = 0; iLeft < iCount - 1; ++iLeft)
{
for(unsigned iRight = iCount - iLeft - 1; iRight > 0; --iRight)
{
if(array[iRight] < array[iRight - 1])
{
int iTmp = array[iRight];
array[iRight] = array[iRight - 1];
array[iRight - 1] = iTmp;
}
else
{
}
}
}
return true;
}
/*
Date: 021909
Author: Kevin
Desc: Bubble Sort
*/
bool BubbleSortR03(int *const array, unsigned int iCount)
{
//Judge whether iCount is a legal number
if(0 > iCount)
{
return false;
}
else
{
}
//main part
for(unsigned uRoundOne = 0; uRoundOne < iCount - 1; ++uRoundOne)
{
for(unsigned uRoundTwo = iCount - uRoundOne - 1; uRoundTwo > 0; --uRoundTwo)
{
if(array[uRoundTwo] < array[uRoundTwo - 1])
{
int iTmp = array[uRoundTwo];
array[uRoundTwo] = array[uRoundTwo - 1];
array[uRoundTwo - 1] = iTmp;
}
else
{
}
}
}
return true;
}
Subscribe to:
Posts (Atom)
