qosort 使用使用小例子

时间:2014-05-01 19:12:33   收藏:0   阅读:358

输入

1
500 3
150 300
100 200

 

输出结果
470 471
100    200
150    300
470    471

 
 
bubuko.com,布布扣
#include <iostream>
#include<stdlib.h>
using namespace std;
struct node
{
    int  a ;
    int b;


}s[100];
int compare(const void *a,const void *b)
{
    node *pa=(node *)a;
    node *pb=(node *)b;
    return   pa->a-pb->a;



}


int main() {

    int len;
    cin>>len;
    while(len--)
    {
        int lenOFroad;
        cin>>lenOFroad;
        int count;
        cin>>count;
        for(int i=0;i<count;i++)
        {
           cin>>s[i].a;
           cin>>s[i].b;

        }

        qsort(s,count,sizeof(node),compare);
        
        for(int i=1;i<count;i++)
        {
            
               cout<<s[i].a<<"\t"<<s[i].b;
        }
        cout<<endl;
                
    }


    return 0;
}
bubuko.com,布布扣

qosort 使用使用小例子,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!