Skip to content

Instantly share code, notes, and snippets.

@CrBoy
Forked from pcyu16/sorting.cpp
Created March 22, 2011 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrBoy/880981 to your computer and use it in GitHub Desktop.
Save CrBoy/880981 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
if(a == 2 && b == 0)
return true;
if(b == 2 && a == 0)
return false;
return a < b;
}
int cmp2(const void *a, const void *b)
{
int x = *(int*)a, y = *(int*)b;
if(x == 2 && y == 0)
return -1;
if(y == 2 && x == 0)
return 1;
return x-y;
}
int main()
{
const int size = 30;
srand(time(NULL));
int ar[size];
for(int i=0;i<size;i++)
ar[i] = rand()%3;
//qsort(ar, size, sizeof(int), cmp2);
sort(ar,ar+size, cmp);
for(int i=0;i<size;i++)
printf(" %d",ar[i]);
putchar('\n');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment