Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用函数对数据进行排序_C++_Sorting_Deque - Fatal编程技术网

C++ 用函数对数据进行排序

C++ 用函数对数据进行排序,c++,sorting,deque,C++,Sorting,Deque,我需要对std::pair的deque进行排序,然后打印出它们原始的未排序迭代器值,但是当我尝试使用以下代码时: // I have used pii instead of pair<int,int> by using typedef inline bool comparison(pii & lval, pii & rval) { return (lval.first < rval.first); } // and a few lines

我需要对std::pair的deque进行排序,然后打印出它们原始的未排序迭代器值,但是当我尝试使用以下代码时:

// I have used pii instead of pair<int,int> by using typedef
inline bool comparison(pii & lval, pii & rval) {
        return (lval.first < rval.first);
    } // and a few lines down
sort(v.begin(),v.end(), comparison);
//我通过使用typedef使用了pii而不是pair
内联布尔比较(pii和lval、pii和rval){
返回(lval.first
我得到以下错误:

错误C2664:'bool(pii&,pii&'):无法将参数2从'const int'转换为'pii&'

我似乎不明白我错在哪里,有人能找出错误吗? 如果要查看完整代码,请单击此处:

#include <cstdio>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> pii;

inline void get_input(deque<pii> place, const int & size) {
    pii temp;
    for (int i = 0; i < size; ++i) {
        scanf("%d", &temp.first);
        temp.second = i;
        place.push_back(temp);
    }
}

inline bool comparison(pii & lval, pii & rval) {
    return (lval.first < rval.first);
}

int main() {
    int n;
    scanf("%d", &n);
    deque<pii> v1, v2;
    get_input(v1, n);
    get_input(v2, n);
    sort(v1.begin(), v1.end(), comparison);
    sort(v2.begin(), v2.end(), comparison);
    /* I am aware that the part where I print the values of
    the iterators is missing, I didn't want to add unimportant
    bulk to the question */
    return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
typedef对pii;
内联void get_输入(deque place、const int和size){
pii温度;
对于(int i=0;i
完整的示例对我来说很好。您使用的编译器和编译器标志是什么?请注意,
inline
不一定会导致函数内联,也不一定会因为缺少
inline
关键字而阻止内联。我想知道哪些编译器在调用
排序
时内联
比较
。您也可以进行签名
比较(const-pii&,const-pii&)
。签名
比较(const-pii&,const-pii&)
更具语义意义——您没有修改任何一个参数,没有理由不使用常量。另一个问题,
get\u input()
应该通过引用获取其第一个参数,否则您将给它一个您的数据的副本,它将填充副本,然后销毁副本,将
main()
中的原始数据保留为空。