Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Data Structures In C++ #TechLunch

Data Structures In C++ #TechLunch

2012/01/04(水) @ Livesense TechLunch
発表者:桂 大介

Livesense Inc.

April 23, 2014
Tweet

More Decks by Livesense Inc.

Other Decks in Technology

Transcript

  1. C++

  2. Domains Systems software Application software Device drivers Embedded software High-performance

    server and client applications Entertainment software such as video games
  3. 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
  4. 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
  5. 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
  6. #include <iostream> #include <queue> using namespace std; int main() {

    queue<int> 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; }
  7. template<class T> 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; };
  8. int main() { typedef Node<int> IntNode; Node<int> head(1); IntNode third

    = 3; head.push(new Node<int>(2)) .push(&third) .push(new Node<int>(4)) .unshift(new IntNode(0)) .unshift(new Node<int>(-1)) .dump(); return 0; }
  9. 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(); } };
  10. 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(); } };