Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Vectors as Inputs to Map
//Title of this code // Vectors as Inputs for Map Containers #include <iostream> #include <map> #include <vector> #include <cstdlib> using namespace std; typedef vector<double>Value; typedef vector<int>Key; typedef map<Key::value_type, Value::value_type, less<Key::value_type> >TMap; template<class T>ostream& operator <<(ostream& out, const vector<T>& v){ for(auto i:v) out << i << " "; return out; }; int main() { int vkSize = 10; Key key(vkSize); Value value(vkSize); TMap map1; double d = 1.0; int j = 1; pair<Key::value_type, Value::value_type>p(key[0], value[0]); // declare and initialize p srand(1); for(int i = 0; i<vkSize; i++){ double f = rand() % 100 + 1.25; d = f/100.0; value[i] = d; // fill value vector key[i] = j; // fill key vector p = make_pair(key[i], value[i]); map1.insert(p); // fill map j++; } cout << "Keys:\t[" << key << "]\n"; cout << "Values:\t[" << value << "]\n\n"; TMap::const_iterator cIt1; cout << "Key\tValue\n\n"; for(int i = 1; i < (vkSize+1); i++){ cIt1 = map1.find(i); cout << cIt1->first << "\t" << cIt1->second << "\n"; } return 0; }
run
|
edit
|
history
|
help
0
Search in a rotated sorted array
Switch case
SegTree
perfect square
1234
11
sorting
C++ lesson
1st
Einstein's Physics