隨手畫了乙個圖小結一下:
下面是根據書中的例子寫的一些**:
#include #include #include "triangulate_iterator.h"
using namespace std;
static int arr[13] = ;
class triangulate_iterator;
class triangulate
int beg_pos() const
int length()
int beg_pos()
bool next(int &x) const;
void next_reset() const;
static bool is_elem( int );
static int get_elem( int pos )
static void gen_elements( int length );
static void gen_elems_to_value( int value );
static void display( int length, int beg_pos, ostream &os = cout );
static vector_elem;
private:
string _name;
int _length;
int _beg_pos;
mutable int _next;
static const int _max_elems = 1024;
};class triangulate_iterator
friend int operator* (const triangulate_iterator &rhs);
bool operator== ( const triangulate_iterator& ) const;
bool operator!= ( const triangulate_iterator& ) const;
int triangulate_iterator::operator* (const triangulate_iterator &rhs);
triangulate_iterator& operator++ ();
triangulate_iterator operator++ ( int );
private:
void check_integrity() const; //檢查 _index是否合理
int _index;
};class iterator_overflow;
int operator* (const triangulate_iterator &rhs)
inline bool triangulate_iterator::operator == ( const triangulate_iterator& rhs ) const
inline bool triangulate_iterator::operator != ( const triangulate_iterator& rhs ) const
inline
int triangulate_iterator::operator* (const triangulate_iterator &rhs)
triangulate_iterator& triangulate_iterator::operator++ ()
triangulate_iterator triangulate_iterator::operator++ ( int )
inline
void triangulate_iterator::check_integrity() const
triangulate_iterator triangulate::begin()
triangulate_iterator triangulate::end()
triangulate::triangulate()
: _name("triangulate"),_length(1),_beg_pos(1),_next(0) {}
triangulate::triangulate(int l, int b) : _name("triangulate")
triangulate::triangulate(int l) : _name("triangulate")
triangulate::triangulate(const triangulate &rhs)
bool triangulate::next(int &elem) const
void triangulate::next_reset() const
vectortriangulate::_elem;
int sum( const triangulate &trian )
bool triangulate::is_elem( int value )
void triangulate::gen_elems_to_value( int value )
if ( ix == 1)
while ( _elem[ix-1] < value && ix < _max_elems)
if( ix == _max_elems )
cerr << " value too large " << value << " -- exceeds max size of "
<< _max_elems << endl;
}void triangulate::gen_elements( int length )
if ( length == 2 && ix < length )
_elem.push_back(1);
++ix;
}for (; ix < length; ix++ )
}int main() else
more = false;
}return 0;
}
第四章學習小結
目標 上次設定的目標是跟著老師邊學邊做題。這個目標已經達成了。接下來的目標是把這個當成自己的學習習慣,因為在跟隨老師的思路做題的時候感覺非常的清晰,debug也沒有那麼辛苦。另外乙個目標就是將老師課上留給同學自己去探索的去學習的內容 學習到位。像這一章的兩道基礎題目有 kmp演算法 和 十字鏈 兩種...
第四章 繼承
一 為什麼要繼承 在物件導向中我們將具有很多重複內容的類中的內容提取出來,寫成乙個單獨的類 其他類只需要繼承就能取得這些功能,同時可以在自己類中寫入獨特的自定義方法 二 繼承語法 inte ce circle nsobject 繼承是在介面中定義的 冒號後的類名是要整合的類,nsobject 是co...
第四章 物件
三個特性 身份 型別 值 每個物件都有唯一的身份來標識自己,使用內建函式id 得到。例子 usr bin env python coding utf 8 a 32 print a b a print id a id b 結果 d python27 python.exe e workp python ...