M
mattg
Hi,
Can somebody explain to me why the code
#include<iostream>
#include<set>
using namespace std;
class node {
public : int val;
node(int v){
val = v;
}
};
struct node_comp{
bool operator () (node * n1, node * n2) const {
return n1->val < n2->val;
}
};
set<node*, node_comp> s1;
void test(){
s1.insert((new node(1)));
s1.insert((new node(2)));
s1.insert(new node(8));
s1.insert(new node(9));
s1.insert(new node(12));
}
int main(){
test();
set<node*, node_comp>::iterator iter;
iter = s1.lower_bound(new node(5));
cout << "iter =" << (*iter)->val << endl;
}
outputs
iter = 8
instead of
iter = 2
?
Can somebody explain to me why the code
#include<iostream>
#include<set>
using namespace std;
class node {
public : int val;
node(int v){
val = v;
}
};
struct node_comp{
bool operator () (node * n1, node * n2) const {
return n1->val < n2->val;
}
};
set<node*, node_comp> s1;
void test(){
s1.insert((new node(1)));
s1.insert((new node(2)));
s1.insert(new node(8));
s1.insert(new node(9));
s1.insert(new node(12));
}
int main(){
test();
set<node*, node_comp>::iterator iter;
iter = s1.lower_bound(new node(5));
cout << "iter =" << (*iter)->val << endl;
}
outputs
iter = 8
instead of
iter = 2
?