This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Variation on the Observer design pattern. | |
| I just want to keep a list of items, and call methods on them. (Similar to observer's notify) | |
| But the items will always be in a list (ie, automatic registration) | |
| Instead of the items requiring to be inside pointers or pointer wrappers, this handles stack allocated | |
| items too, and items inside std containers, using copy and move semantics. | |
| Uses C++11 features, compile with gcc -std=c++11 or equivalent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <map> | |
| #include <vector> | |
| #include <stdexcept> | |
| class Cell | |
| { | |
| //... (Make sure its copy constructable, or moveable) | |
| }; | |
| class Map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <fstream> | |
| #include <string> | |
| #include <sstream> | |
| #include <vector> | |
| #include <map> | |
| using namespace std; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set tabstop=4 | |
| set shiftwidth=4 "to make << and >> indent to the same size as tabstop | |
| set guifont=DejaVu_Sans_Mono:h9:cANSI | |
| set number | |
| set nowrapscan "stop wraparound on searches, I frequently miss the message | |
| syntax on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** | |
| Are vectors or linked lists faster? | |
| Algorithm: | |
| insert MAX_COUNT random numbers, sorting in place as we go | |
| delete the (random between 0 and current size-1)th element MAX_COUNT times | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using std::cout; | |
| using std::endl; | |
| using std::string; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <sstream> | |
| using std::cout; | |
| using std::endl; | |
| using std::string; | |
| using std::stringstream; | |
| bool IsPalindrome(const string &s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void GenShape() | |
| { | |
| const float radius = 64.0f; | |
| //const float sine[] = { 0.0f, 1.0f, 0.0f, -1.0f }; | |
| const float sine[] = { 0.0f, 0.7f, 1.0f, 0.7f, 0.0f, -0.7f, -1.0f, -0.7f }; | |
| //const float sine[] = { 0.0f, 0.4f, 0.7f, 0.9f, 1.0f, 0.9f, 0.7f, 0.4f, 0.0f, -0.4f, -0.7f, -0.9f, -1.0f, -0.9f, -0.7f, -0.4f }; | |
| const int segments = sizeof(sine) / sizeof(sine[0]); |