Created
March 22, 2011 09:25
-
-
Save pcyu16/880979 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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