Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
АФТИ ООП 2013-2014. Лекция II/1
Search
Oleg Dashevskii
February 17, 2014
Education
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
АФТИ ООП 2013-2014. Лекция II/1
Oleg Dashevskii
February 17, 2014
More Decks by Oleg Dashevskii
See All by Oleg Dashevskii
Лекция № 13. Практическое руководство по разработке
be9
0
1.6k
Лекция № 12. Ещё о проектировании
be9
0
1.5k
Лекция № 11. Принцип отделения интерфейса. «Малое ООП»
be9
0
1.6k
Лекция № 10. Графическая нотация. Принципы LSP и DIP
be9
0
1.6k
Лекция № 9. Отношения между классами. Принцип открытия-закрытия
be9
0
1.5k
Лекция № 8. Хорошие и плохие ОО-программы
be9
0
1.5k
Лекция № 7. algorithm. Исключения
be9
1
1.5k
Лекция № 6. Стандартная библиотека C++. Часть 2
be9
0
1.6k
Лекция № 5. Стандартная библиотека C++. Часть 1
be9
0
1.7k
Other Decks in Education
See All in Education
輻射安全管理系統2.0暨輻防e++學園平台說明會
aecrp
0
2k
[2026前期火5] 論理学(京都大学文学部 前期 第6回)「かつとまたはの規則」
yatabe
0
510
Πλουτοκρατία: Η Τυραννία του Μαμμωνά και η Μεταανθρώπινη Δουλεία
amethyst1
0
310
批判的応用言語学ワークショップ(2026-08-12 お茶の⽔⼥⼦⼤学)
terasawat
0
190
NDIAS Automotive / IoT CTF 2026 Recap - Keyfob & OSINT
himitu23
0
340
2026年度春学期 統計学 第11回 分布の「型」を考える - 確率分布モデルと正規分布 (2026. 6. 11)
akiraasano
PRO
0
180
AIがコードを書く時代に、何を教えるのか / What Should We Teach in the Age of AI-Generated Code?
ichiroc
1
560
AIでアウトプットできる時代だからこそ、自分の言葉で考えることの大切さ / What's Left to Think, When AI Can Write?
masakiokuda
1
290
データマネジメント試験対策教材1〜データマネジメント基礎〜
yoshimura_datam
1
730
INTRODUCTION TO THE CELL
pawan5505
0
270
Comentario del plano urbano de Madrid hasta 1860 (1ª parte )
juanmartin2026
1
71k
Plano urbano de Madrid desde el Ensanche al s. XXI (2ª parte).
juanmartin2026
1
71k
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
930
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Embracing the Ebb and Flow
colly
88
5.2k
Documentation Writing (for coders)
carmenintech
77
5.5k
GraphQLとの向き合い方2022年版
quramy
50
15k
How to make the Groovebox
asonas
2
2.4k
How STYLIGHT went responsive
nonsquared
100
6.3k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
590
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.2k
Transcript
ОБЪЕКТНО- ОРИЕНТИРОВАННОЕ ПРОГРАММИРОВАНИЕ Лекция № 2/1 17.02.2014 г.
СТАНДАРТНЫЕ КОНТЕЙНЕРЫ • Готовые, протестированные, эффективные, настраиваемые реализации распространенных структур
данных уже есть. • «Вы просто не умеете их готовить».
АТРИБУТЫ КОНТЕЙНЕРОВ • Линейность/нелинейность • Произвольный доступ • Упорядоченность •
«Специфичность»
ОПЕРАЦИИ • Вставка • Удаление • Поиск по ключу •
Доступ по индексу • Обход
STD::VECTOR • Динамический массив. • Оптимизирован для вставки. std::vector<int> numbers;!
! for (int i = 0; i < 100000; ++i)! ! numbers.push_back(i);
void push_back(const value_type& __x)! {! if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)! {!
this->_M_impl.construct(this->_M_impl._M_finish, __x);! ! ++this->_M_impl._M_finish;! }! else! _M_insert_aux(end(), __x);! }!
vector<int>::const_iterator it;! ! for (it = numbers.begin(); it != numbers.end();
++it)! ! cout << *it << ' ';!
template<typename _Iterator, typename _Container>! class __normal_iterator {! protected:! ! _Iterator
_M_current;! ! public:! ! // ...! ! typedef typename iterator_traits<_Iterator>::reference reference;! ! typedef typename iterator_traits<_Iterator>::pointer pointer;! ! ! __normal_iterator() : _M_current(_Iterator()) { }! ! ! reference operator*() const { return *_M_current; }! ! pointer operator->() const { return _M_current; }! ! ! __normal_iterator& operator++() {! ! ! ++_M_current; ! ! ! return *this;! ! }! ! // ...! };!
vector<vector<double> > matrix;
STD::LIST • Двусвязный (кольцевой) список
struct _List_node_base {! ! _List_node_base* _M_next; ///< Self-explanatory! ! _List_node_base*
_M_prev; ///< Self-explanatory! ! ! // ....! };! ! template<typename _Tp>! struct _List_node : public _List_node_base {! ! _Tp _M_data; ///< User's data.! };!
list<int>::const_iterator it;! ! for (it = numbers.begin(); it != numbers.end();
++it)! ! cout << *it << ' ';! vector<int>
template<typename _Tp>! struct _List_iterator! {! ! typedef _List_iterator<_Tp> _Self;! !
typedef _List_node<_Tp> _Node;! ! ! typedef _Tp* pointer;! ! typedef _Tp& reference;! ! ! _List_iterator() : _M_node() { }! ! ! explicit _List_iterator(_List_node_base* __x) : _M_node(__x) { }! ! ! // Must downcast from List_node_base to _List_node to get to _M_data.! ! reference operator*() const { return static_cast<_Node*>(_M_node)->_M_data; }! ! ! pointer operator->() const { return &static_cast<_Node*>(_M_node)->_M_data; }! ! ! _Self& operator++() {! ! ! _M_node = _M_node->_M_next;! ! ! return *this;! ! }! ! ! _List_node_base* _M_node;! }!
STD::MAP • Ассоциативный массив: ключ → значение. • Реализован на
базе красно-черных деревьев. • Ключи должны быть сравниваемы.
std::map<std::string, int> count_words() ! {! ! std::string word;! ! std::map<std::string,
int> counts;! ! ! while (word = get_word(), !word.empty()) {! ! ! std::map<std::string, int>::iterator it = counts.find(word);! ! ! ! if (it == counts.end())! ! ! ! counts[word] = 1;! ! ! else! ! ! ! ++it->second;! ! ! }! ! ! return counts;! }! template<class _T1, class _T2>! struct pair {! ! typedef _T1 first_type;! ! typedef _T2 second_type;! ! ! _T1 first;! ! _T2 second;! ! ! // ....! };!
map<string, int>::const_iterator it;! ! for (it = counts.begin(); it !=
counts.end(); ++it)! ! cout << it->first << ": " << it->second << endl;!
enum _Rb_tree_color { _S_red = false, _S_black = true };!
! struct _Rb_tree_node_base {! typedef _Rb_tree_node_base* _Base_ptr;! ! _Rb_tree_color _M_color;! _Base_ptr _M_parent;! _Base_ptr _M_left;! _Base_ptr _M_right;! ! // ....! };!
template<typename _Tp>! struct _Rb_tree_iterator {! ! typedef _Tp value_type;! !
typedef _Tp& reference;! ! typedef _Tp* pointer;! ! typedef _Rb_tree_iterator<_Tp> ! _Self;! ! typedef _Rb_tree_node<_Tp>* _Link_type; ! ! ! reference operator*() const { ! ! ! return static_cast<_Link_type>(_M_node)->_M_value_field;! ! }! ! ! _Self operator++(int) {! ! ! _Self __tmp = *this;! ! ! _M_node = _Rb_tree_increment(_M_node);! return __tmp;! ! }! };!
static _Rb_tree_node_base *local_Rb_tree_increment(_Rb_tree_node_base* __x) {! ! if (__x->_M_right != 0)
{! ! ! __x = __x->_M_right;! ! ! while (__x->_M_left != 0)! __x = __x->_M_left;! ! } else {! _Rb_tree_node_base* __y = __x->_M_parent;! while (__x == __y->_M_right) {! __x = __y;! __y = __y->_M_parent;! ! ! }! if (__x->_M_right != __y)! __x = __y;! }! return __x;! }!
ТОНКОСТИ СРАВНЕНИЙ template <typename _Key, typename _Tp, ! typename _Compare
= std::less<_Key>,! typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >! class map {! public:! ! typedef _Key key_type;! ! typedef _Tp mapped_type;! ! typedef std::pair<const _Key, _Tp> value_type;! ! typedef _Compare key_compare;! ! typedef _Alloc allocator_type;! ! ! // ....! };!
template <class _Arg1, class _Arg2, class _Result>! struct binary_function! {!
! typedef _Arg1 first_argument_type;! ! typedef _Arg2 second_argument_type;! ! typedef _Result result_type;! };! ! template <class _Tp>! struct less : public binary_function<_Tp, _Tp, bool> {! ! bool operator()(const _Tp& __x, const _Tp& __y) const {! ! ! return __x < __y;! ! ! }! };!
struct Address {! string city, details, postal_index;! ! Address(const string
&_city, const string &_details = string(),! const string _index = string())! : city(_city), details(_details), postal_index(_index) {}! };! ! struct Person {! // .....! };! !
struct CityCompare {! bool operator()(const Address &a1, const Address &a2)
const {! return a1.city < a2.city;! }! };! ! void add_karma_to_novosibirsk_people(! vector<pair<Address, Person> > people_and_addresses) {! typedef multimap<Address, Person, CityCompare> AdrMap;! ! AdrMap addresses_by_city;! ! for (int i = 0; i < people_and_addresses.size(); ++i)! addresses_by_city.insert(people_and_addresses[i]);! ! pair<AdrMap::const_iterator, AdrMap::const_iterator> nsk_range =! addresses_by_city.equal_range(Address("Novosibirsk"));! ! // Yay, Novosibirsk people!!! for (AdrMap::const_iterator it = nsk_range.first;! it != nsk_range.second; ++it)! !add_karma(it->second, 100);! }!
ПРОЧИЕ КЛАССЫ • set<Key> – примерный аналог map<Key, bool> •
Аналогично c multiset<Key>. • deque<T> – double-ended queue. Оптимизирован для push_front(). • queue и stack сделаны как адаптеры.
template<typename _Tp, typename _Sequence = deque<_Tp> >! class stack {!
protected:! _Sequence c;! ! public:! typedef typename _Sequence::reference reference;! ! bool empty() const { return c.empty(); }! size_type size() const { return c.size(); }! ! reference top() { return c.back(); }! void push(const value_type& __x) { c.push_back(__x); }! void pop() { c.pop_back(); }! ! // ...! };