Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::qsort

 

std::qsort is a function to sort a container.

 

 

#include <cstdlib>
#include <vector>

int QsortIntCompare(const void * a, const void * b)
{
  const int x = *static_cast<const int*>(a);
  const int y = *static_cast<const int*>(b);
  if (x < y) return -1;
  if (x > y) return  1;
  return 0;
}

///Sort a std::vector using std::qsort
void Qsort(std::vector<int>& v)
{
  std::qsort(&v[0],v.size(),sizeof(int),QsortIntCompare);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml