add c++11 (#87)
* binary search c++ * selection sort c++11 * c++ recursive countdown * c++ recursion * c++ quicksort * rename folder names to c++11 * add another version of binary_search function * c++11 hash tables * c++11 breadth-first search
This commit is contained in:
20
05_hash_tables/c++11/01_price_of_groceries.cpp
Normal file
20
05_hash_tables/c++11/01_price_of_groceries.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main() {
|
||||
std::unordered_map<std::string, float> book = {
|
||||
{"apple", 0.67},
|
||||
{"milk", 1.49},
|
||||
{"avocado", 1.49}
|
||||
};
|
||||
|
||||
// print book
|
||||
for (std::pair<std::string, float> pair : book) {
|
||||
cout << pair.first << ": " << pair.second << "$" << endl;
|
||||
}
|
||||
}
|
||||
24
05_hash_tables/c++11/02_check_voter.cpp
Normal file
24
05_hash_tables/c++11/02_check_voter.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
std::unordered_map<std::string, bool> voted;
|
||||
|
||||
void check_voter(const std::string& name) {
|
||||
auto search = voted.find(name);
|
||||
if (search == voted.end() || search->second == false) {
|
||||
voted.insert({name, true});
|
||||
cout << "Let them vote!" << endl;;
|
||||
} else {
|
||||
cout << "Kick them out!" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
check_voter("tom");
|
||||
check_voter("mike");
|
||||
check_voter("mike");
|
||||
}
|
||||
Reference in New Issue
Block a user