#include #include #include #include #include #include "game_board.h" using std::cout; using std::endl; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::string; using std::vector; void display_vector(const vector& vec, const string& name) { cout << "[" << name <<"] Size: " << vec.size() << " Capactiy: " << vec.capacity() << endl; } // vector vec(3); // void vector_example() { vector vec = {10, 20, 30}; vec.reserve(500); string vec_name("Vec 1"); vector vec2; string vec2_name("Vec 2"); display_vector(vec, vec_name); display_vector(vec2, vec2_name); vec2.push_back(2); display_vector(vec, vec_name); display_vector(vec2, vec2_name); cout << endl << "Vec2 changing capacties:" << endl; for (int i = 0; i < 10; i++) { vec2.push_back(i); display_vector(vec2, vec2_name); } cout << endl << "Values within the vectors:" << endl; // [begin, end) for (vector::iterator it = vec2.begin(); it != vec2.end(); it++) { cout << *it << ", "; } cout << endl; for (vector::iterator it = vec.begin(); it != vec.end(); it++) { cout << *it << ", "; } cout << endl; } // stl containers emplace // vector v; // v.push_back() // m.insert(pair) // v.emplace(int) // (int) // K, V 1int 2int // m.emplace(int,int,int) void map_example() { map m({{"woof", "bark"}, {"meow", "purr"}}); m["hello"] = "hi"; // Constructs the key value pair m["BLAH"]; m.insert({"evening", "eve'nin"}); m.insert(make_pair("goodbye", "bye")); m.insert(pair("shoo", "leave")); for (map::const_iterator it = m.cbegin(); it != m.cend(); it++) { cout << it->first << ", " << it->second << endl; } map::iterator it = m.find("hello"); if (it != m.end()) { cout << "FIND: " << it->first << ", " << it->second << endl; } map::iterator it2 = m.find("asdfasdfa"); if (it2 != m.end()) { cout << "FIND: " << it2->first << ", " << it2->second << endl; } else { cout << "FIND: failed" << endl; } // If key does not exsist, create the value cout << m["DNE"].size() << endl; } template void print_queue(T& q) { while(!q.empty()) { cout << q.top() << " "; q.pop(); } cout << endl; } void priority_queue_example() { priority_queue q; // < for(int n : {1,8,5,6,3,4,0,9,7,2}) q.push(n); print_queue(q); priority_queue, std::greater> q2; for(int n : {1,8,5,6,3,4,0,9,7,2}) q2.push(n); print_queue(q2); // Using lambda to compare elements. auto cmp = [](int left, int right) { return (left ^ 1) < (right ^ 1);}; priority_queue, decltype(cmp)> q3(cmp); for(int n : {1,8,5,6,3,4,0,9,7,2}) q3.push(n); print_queue(q3); } // __x < __y // void custom_pq_example() { priority_queue q; for (int n : {1,8,5,6}) { q.push(GameBoard(5, 25, n)); } print_queue(q); } int main() { // vector_example(); // map_example(); // priority_queue_example(); custom_pq_example(); }