I was doing a problem earliar. we were given an array and were required to find the pairs whose sum is equal to an integer. Now this is my solution:
vector<vector<int,int> > pairSum(vector<int> &arr, int s){
sort(arr.begin(),arr.end());
vector<vector<int,int> > pairs;
int *p=&arr[0];
int *q=&arr[arr.size()-1];
while(p!=q){
if(*p+*q>s){
q--;
}
else if(*p+*q<s){
p++;
}
else if(*p+*q==s){
vector<int> temp;
int a=*p,b=*q;
temp.push_back(a);
temp.push_back(b);
pairs.push_back(temp);
if(p!=p+1 && q!=q-1){
p++;
q--;}
else if(p=p+1){
p++;
}
else if(q=q-1){
q--;
}
}
}
return pairs;
}
But I keep getting the error
‘int’ is not a class, struct, or union type|
and it opens a header file named alloc_traits,h and shows this error
i just realised there is a error at the end of the function in the way im comparing the values , i fixed it but im still getting the same error.
Please post the complete error verbatim – all text lines.
How do i post that?
vector<vector<int,int> > pairs;
. What isvector<int, int>
supposed to do?else if(p=p+1)
,else if(q=q-1)
– are you sure this is what you wanted ? It’s better to separate assignment from condition checking.Show 8 more comments