Maps:
maps<int,int> m;
m[key1] = value1;
m[key2] = value2;
How to iterate
for(map<int,int>::iterator it = m.begin() ; it != m.end(); it++){
cout<<"Key is "<<it->first<<" ";
cout<<"Value is "<<it->second<<endl;
}
List:
maps<int,int> m;
m[key1] = value1;
m[key2] = value2;
How to iterate
for(map<int,int>::iterator it = m.begin() ; it != m.end(); it++){
cout<<"Key is "<<it->first<<" ";
cout<<"Value is "<<it->second<<endl;
}
List:
list<int> *adj = new list<int>[size];
adj[index1].push_back(value);
for(list<int>::iterator i = g->adj[u].begin(); i!=g->adj[u].end(); ++i){
cout<<"->"<<*i;
}
Overload < operator for Sort() Function
class freq
{
public:
int data;
int count;
};
inline bool operator<(const freq& a, const freq& b)
{
return a.count <= b.count;
}
sort(arr,arr+n);
Overload < operator for Sort() Function
class freq
{
public:
int data;
int count;
};
inline bool operator<(const freq& a, const freq& b)
{
return a.count <= b.count;
}
sort(arr,arr+n);
No comments:
Post a Comment