Random code snippet
I just happened to dig up a piece of code from little while ago. This was collaboratively produced in one of the ACM Programming Training events at SUITS. It is designed to remove all duplicate integers from an array. This method has a time complexity of O(nlogn), and memory O(1). Unfortunately, we haven’t tested or compiled it yet…
#include <stdlib.h>
void blah(int *nums, int*size)
{
   int *a, *b;
   qsort((void *)nums, *size, sizeof(int), &cmp);
   for (a = nums + 1, b = nums; a < (nums + *size); a++)
   {
      for (; *a == *b; a++);
      b++;
      *b = *a;
   }
   *size = (b - nums) + 1;
}
int cmp(const void *a; const void *b)
{
   int a, b;
   a = *(int *) a;
   b = *(int *) b;
   return (a == b) ? 0 : ((a < b) ? -1 : 1);
}