[OCLUG-devel] Re: [OCLUG] C - Pointer assignment
Chris Smith
cbsmith at gmail.com
Mon May 23 13:53:40 PDT 2005
On 5/23/05, Doug Jolley <ddjolley at gmail.com> wrote:
> In my latest project I want to perform a buble sort on an array of
> pointers.
I missed this from the original post. So that explains the myPtr part
of it. So you want to sort the pointers based on their address value?
The code isn't going to very different from the same code for
integers:
void bubbleSort(void** array, size_t length)
{
size_t i, j;
for (i = length - 1; i > 0; --i) {
for (j = 0, j < i, ++j) {
if (array[j] > array[j+1]) {
void* temp = array[j];
array[j] = array [j+1];
array[j+1] = temp;
}
}
}
}
Really, if you replace all occurences of "void*" with "int", it's
exactly like sorting integers.
--
Chris
More information about the OCLUG-devel
mailing list