Compile

nasm -f elf sort.asm
g++ -Wall -c test.cpp
g++ test.o sort.o

The int version uses it’s own comparator function :

int intCompare(int* ptrA,int* ptrB) // this is our custom comparator
{
  if(ptrA && ptrB)
  {
    printf("compare %i with %i \n",*ptrA,*ptrB);
    return *ptrA-*ptrB;
  }
  else
  {
     return 1;
   }
}

 

  int init[] = {10,7,5,97,2,3,48,2};
  Array<int,8> a(init);
  a.QuickSort(&intCompare);

compare 10 with 97
compare 7 with 97
compare 5 with 97
compare 97 with 97
compare 2 with 97
compare 2 with 97
compare 3 with 97
compare 48 with 97
compare 97 with 97
compare 48 with 97
compare 10 with 2
compare 48 with 2
compare 3 with 2
compare 2 with 2
compare 7 with 2
compare 2 with 2
compare 5 with 2
compare 5 with 2
compare 2 with 2
compare 2 with 2
compare 2 with 2
compare 5 with 10
compare 7 with 10
compare 10 with 10
compare 48 with 10
compare 3 with 10
compare 5 with 7
compare 7 with 7
compare 3 with 7
compare 5 with 5
compare 3 with 5
compare 10 with 10
compare 48 with 10
compare 10 with 10

Advertisements
This entry was posted in Számítógép és internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s