#define inandout#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include<time.h>using namespace std ;#define Max 10000000int cmp(const void*a,const void* b)//这里实现了多维数组排序,其实有结构体了无所谓{ int c=*((int *)a+1); int d=*((int *)b+1); return c-d;}int node[Max+1][3]={{1,2,3},{2,3,3},{8,5,0},{3,1,3},};int main(){ #ifdef inandout freopen("C:\\Users\\Sky\\Desktop\\1.in","r",stdin); #endif srand(time(NULL)); for(int i=0;i<Max;i++) { node[i][0]=rand()%100; node[i][1]=rand()%100; node[i][2]=rand()%100; } qsort(*node,Max,sizeof(int[3]),cmp); /*for(int j=0;j<=100;j++) { for(int i=0;i<3;i++) { printf("%d ",node[j][i]); } printf("\n"); }*/ printf("Time used = %.0lf ms\n",(double)(1000*clock()/CLOCKS_PER_SEC)); return 0;}
#define inandout#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include<time.h>#define Max 10000000using namespace std ;struct node{ int a; int b; int c;};int cmp(const void*a,const void* b){ node c=*(node *)a; node d=*(node *)b; return c.b-d.b;}int cmp2(node a,node b){ return a.b<b.b;} node k[Max+1]={{1,2,3},{2,3,3},{8,5,0},{3,1,3},};int main(){ #ifdef inandout freopen("C:\\Users\\Sky\\Desktop\\1.in","r",stdin); #endif srand(time(NULL));
for(int i=0;i<Max;i++) { k[i].a=rand()%100; k[i].b=rand()%100; k[i].c=rand()%100; } sort(&k[0],&k[Max],cmp2);// qsort(k,Max,sizeof(k[0]),cmp); /*for(int j=0;j<=100;j++) { printf("%d %d %d",k[j].a,k[j].b,k[j].c); printf("\n"); }*/ printf("Time used = %.0lf ms\n",(double)(1000*clock()/CLOCKS_PER_SEC)); return 0;}
转载于:https://www.cnblogs.com/Skyxj/p/3178671.html