随笔分类 -  c/c++

摘要:CSAPPint tadd_ok(int x, int y){ int sum = x + y; int neg_over = x = 0; int pos_over = x >= 0 && y >= 0 && sum = 0 || (x^b) >= 0) retur... 阅读全文
posted @ 2014-04-13 23:10 macula7 阅读(603) 评论(0) 推荐(0)
摘要:accumulate 累加序列的所有元素adjacent_difference 计算序列中的相邻元素是否不同adjacent_find 查找相邻的两个相同(或者有其他关联)元素binary_search 确定容器中是否存在某个元素copy 拷贝元素到新的位置copy_backward 逆序拷贝元素count 返回匹配给定值的元素数目count_if 返回符合条件的元素数目equal 确定两个集合中的所有元素皆相同equal_range 搜索序列中的由相同元素组成的子序列fill 为一个序列赋值fill_n 为序列中给定数目的元素赋值find 在序列中查找一个匹配值的元素find_end 在序列 阅读全文
posted @ 2011-04-13 23:24 macula7 阅读(1570) 评论(0) 推荐(0)
摘要:merge:template <class InputIterator1, class InputIterator2, class OutputIterator> OutputIterator merge ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result );template <class InputIterator1, class InputIterator2, class OutputIterat 阅读全文
posted @ 2011-04-13 23:21 macula7 阅读(495) 评论(0) 推荐(0)
摘要:sort(排序):template <class RandomAccessIterator> void sort ( RandomAccessIterator first, RandomAccessIterator last );template <class RandomAccessIterator, class Compare> void sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp );该方法用于排序,comp用于指定元素比较的函数类似的有stable_sort 阅读全文
posted @ 2011-04-13 10:25 macula7 阅读(354) 评论(0) 推荐(0)
摘要:copy:#include <algorithm>template< class InputIterator, class OutputIterator >OutputIterator copy( InputIterator first, InputIterator last, OutputIterator d_first );该方法会将first到last之间的元素拷贝到d_first之中~~相当于如下实现:template<class InputIterator, class OutputIterator>OutputIterator copy(Inpu 阅读全文
posted @ 2011-04-12 22:10 macula7 阅读(312) 评论(0) 推荐(0)
摘要:for_eachFunction for_each (InputIterator first, InputIterator last, Function f);将函数f应用于first和last之间的元素。相当于如下的行为template<class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function f) { for ( ; first!=last; ++first ) f(*first); return f; }可以如下应用:#inc 阅读全文
posted @ 2011-04-12 20:19 macula7 阅读(473) 评论(2) 推荐(1)
摘要:希望打印出如下的图形:parisin thesprint+------+|paris ||in the||sprint|+------+paris +------+in the|paris |sprint|in the| |sprint| +------+parisin thesprint+------+|paris ||in the||sprint|+------+第一个图形,第二个代表队图形加边框,第三个代表了图形的左右连接,第三个代表图形的上下连接。程序调用如下:#include "Picture.h"char *init[] = {"paris" 阅读全文
posted @ 2011-03-01 00:25 macula7 阅读(208) 评论(0) 推荐(0)
摘要:在c++沉思录举了一个表达式树的例子,将例如(-5)*(3+4)的式子表示成树的形式。可以通过如下形式:Expr t = Expr("*", Expr("-", 5), Expr("+", 3, 4));cout<<t<<" = "<<t.eval()<<endl;创建树并将树打印出来。这个程序主要用于理解动态绑定和句柄,程序实现代码如下:#include <iostream>#include <string>/*所有节点类型的父类 */cla 阅读全文
posted @ 2011-02-28 14:44 macula7 阅读(318) 评论(0) 推荐(0)
摘要:#include <iostream>class Point{public: Point():xv(0),yv(0){} Point(int a, int b):xv(a), yv(b){} Point(const Point &p):xv(p.xv), yv(p.yv){} int x() const {return xv;} int y() const {return yv;} Point & x(int x){xv = x; return *this;} Point & y(int y){yv = y; return *this;}private: i 阅读全文
posted @ 2011-02-25 14:34 macula7 阅读(756) 评论(0) 推荐(0)