Slide 1

Slide 1 text

Data Structures In C++ Data Structures In C++ [email protected]

Slide 2

Slide 2 text

C++

Slide 3

Slide 3 text

Bjarne Stroustrup Bjarne Stroustrup

Slide 4

Slide 4 text

Philosophy Statically typed Free-form Multi-paradigm Compiled General-purpose

Slide 5

Slide 5 text

Domains Systems software Application software Device drivers Embedded software High-performance server and client applications Entertainment software such as video games

Slide 6

Slide 6 text

Features Classes Virtual Functions Operator overloading Multiple Inheritance Templates Exception handling

Slide 7

Slide 7 text

C++11

Slide 8

Slide 8 text

Core language usability enhancements Initializer lists Uniform initialization Type inference( 型推論 ) Range-based for-loop Lambda functions and expressions Alternative function syntax Object construction improvement Explicit overrides and final Identifiers with special meaning Null pointer constant Strongly typed enumerations Right angle bracket Explicit conversion operators Alias templates Unrestricted unions

Slide 9

Slide 9 text

Core language functionality improvements Variadic templates New string literals User-defined literals Multitasking memory model Thread-local storage Explicitly defaulted and deleted special member functions Type long long int Static assertions Allow sizeof to work on members of classes without an explicit object Allow garbage collected implementations

Slide 10

Slide 10 text

C++ standard library changes Upgrades to standard library components Threading facilities Tuple types Hash tables Regular expressions General-purpose smart pointers Extensible random number facility Wrapper reference Polymorphic wrappers for function objects Type traits for metaprogramming Uniform method for computing the return type of function objects

Slide 11

Slide 11 text

#include void main() { std::cout << "Hello, world!\n"; }

Slide 12

Slide 12 text

Data Structures

Slide 13

Slide 13 text

Queue

Slide 14

Slide 14 text

#include #include using namespace std; int main() { queue q; q.push(1); q.push(2); q.push(3); q.push(4); int size = q.size(); for (int i = 0; i < size; i++) { cout << q.front() << endl; q.pop(); } return 0; }

Slide 15

Slide 15 text

Linked list

Slide 16

Slide 16 text

template class Node { public: Node(T v) : value(v), next() {} void dump() { cout << value << endl; if (next) { next->dump(); } } Node &push(Node *n) { Node *last = this; while (last->next) last = last->next; last->next = n; return *this; } Node &unshift(Node *n) { n->next = this; return *n; } private: T value; Node *next; };

Slide 17

Slide 17 text

int main() { typedef Node IntNode; Node head(1); IntNode third = 3; head.push(new Node(2)) .push(&third) .push(new Node(4)) .unshift(new IntNode(0)) .unshift(new Node(-1)) .dump(); return 0; }

Slide 18

Slide 18 text

Binary search tree

Slide 19

Slide 19 text

class Node { private: int value; Node *left; Node *right; public: Node(int v) { value = v; left = right = NULL; } void add(int v) { Node **target = value >= v ? &left : &right; if (*target) { (*target)->add(v); } else { *target = new Node(v); } } void dump() { if (left) left->dump(); cout << value << endl; if (right) right->dump(); } };

Slide 20

Slide 20 text

class Tree { private: Node *root; public: Tree(int v) { root = new Node(v); } Tree add(int v) { root->add(v); return *this; } void dump() { root->dump(); } };

Slide 21

Slide 21 text

int main() { Tree tree(5); tree.add(6) .add(3) .add(10) .add(1) .add(8) .dump() ; return 0; }

Slide 22

Slide 22 text

次回テーマ

Slide 23

Slide 23 text

Memcached or Mongo あたりで コードリーディング