自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(99)
  • 收藏
  • 关注

原创 已将博客迁移至博客园, 但关联的代码片还在这

一开始

2014-11-15 17:14:00 501

原创 Default Constructor 的建构操作

default constructor 会在需要的时候被编译器产生出来 ---->那么问题来了, 是在谁需要的时候? 考察以下代码:class Foo{public: int val; Foo *pnext};void FooBar(){//Foo Object 须在此初始化Foo bar;if(bar.val || bar.pnext)//do

2014-11-14 14:42:54 384

原创 TC++PL's Advices(1)

全为自己翻译, 如有不妥, 望请斧正.Programming In C++:[1]  Represent ideas directly in code.[2]  Represent relationships among ideas directly in code (e.g., hierarchical, parametric, andownership relationship

2014-11-11 22:54:37 461

原创 C++ 中可确定的内置类型的大小关系

1 ≡ sizeof(char) ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long)• 1 ≤ sizeof(bool) ≤ sizeof(long)• sizeof(char) ≤ sizeof(wchar_t) ≤ sizeof(long)• sizeof(float) ≤ siz

2014-11-11 18:41:29 406

原创 集合内查找的四种方式

//loop & checkvar products = Product.GetSampleProducts();foreach (var product in products) if (product.Price > 10m) Console.WriteLine(product);//defined the rule, got target list,

2014-11-11 16:19:19 471

原创 C++ 零散知识

全局变量的初始化时机: C 是在编译期初始化, C++ 是在程序运行时, main 函数之前初始化.不使用中间变量实现 strlen:int MyStrlen (const char *str){return *str? MyStrlen(++str) + 1 : 0;}C 语言函数参数入栈顺序为从右至左。具体原因为:C 方式参数入栈顺序(从右至左)的好处就是可以动

2014-11-11 13:19:39 291

原创 List 排序的四种方式

class Product{ readonly string name; public string Name { get { return name; } } readonly decimal price; public decimal Price { get { return price; } } public Product(st

2014-11-10 18:37:46 397

原创 对于 sizeof(class_name) 值的讨论

之前遇到过一个问题, 说是 sizeof(class_name) 的值是多少, 不解.But, 在看了 > 有所理解之后, 对于这个问题我得到了似乎正确的答案, 现总结如下, 如有不妥, 望请斧正(虽说我觉得几乎没人会看我的博客吧......= =)对了, 要求严肃的朋友请直接跳过括号内容, 嗯......对于一个 class A, sizeof(A) 是什么意思呢?

2014-11-07 01:58:15 428

原创 STL 标准容器的选择

1. 除非有很好的理由选择其他容器, 否则应使用 vector.2.如果有很多小的元素, 且空间的额外开销很重要, 则不要使用 list 或 forward_list.3.如果程序要求随机访问元素, 应使用 vector 或 list.4.如果程序需要在头尾 插入/删除 元素,且不会在中间插入元素, 则使用 deque5.如果需要在中间插入元素, 应使用 list 或 forwar

2014-11-05 21:49:56 279

原创 求最大公约数

//最大公约数int gcd(int p, int q){ if(q){ int r = p % q; return gcd(q, r); } return p;}

2014-11-05 13:47:28 245

原创 输出100以内所有素数(待改进)

set iset;for (size_t i = 2; i != 100; ++i) iset.insert(i);copy_if (iset.cbegin (), iset.cend (), ostream_iterator (cout, " "), [] (int a){ for (int i = 2; i < sqrt (a); ++i) i

2014-11-05 12:57:28 366

原创 求用32位 int 能表示的最大 n! 的值

#include #include using namespace std;long long foo (int n){ if (n)return foo (n - 1) * n; return 1;}int bar (){ int n = 0; while(foo (++n) ::max)()); return n - 1;}

2014-11-04 22:40:51 558

原创 希尔排序实现(不太满意)

templatevoid ShellSort (Container &container){ const int container_len = container.size (); int sub_container_len = 1; //设置合适的sub_container_len while (sub_container_len < container_len / 3

2014-11-03 23:23:51 301

原创 插入排序实现

templatevoid InsertSort (Container &container){ for (int i = 1; i < container.size (); ++i) for (int j = i; j > 0 && container[j] < container[j - 1]; --j) swap (container[j], container[j

2014-11-03 23:21:10 246

原创 选择排序实现

templatevoid SelectionSort (Container &container){ for (auto i = container.begin (); i != container.cend (); ++i) { auto min = i; for (auto j = i + 1; j != container.cend (); ++j) if (

2014-11-03 23:19:37 277

原创 使用 ^ 位运算符交换值的细节

void inplace_swap(int *a, int *b){ *a = *a ^ *b; // step1 *b = *a ^ *b; // step2 *a = *a ^ *b; // step3}/* *已知: a ^ a = 0; *value *a *b *step0 a

2014-10-30 21:41:53 373

原创 用位运算实现 | 与 ^ 的功能

已知有 bis 和 bic 两种指令,

2014-10-30 17:22:51 308

原创 如何初始化一个定长List<T>

List list = new List(new T[n]);

2014-09-28 02:41:22 3407

原创 设计模式-命令模式

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CSharp{ class Program { public interface Comma

2014-09-28 02:36:42 294

原创 设计模式-装饰模式

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CSharp{ class Program { public abstract class

2014-09-28 01:42:41 316

原创 设计模式: 观察者模式

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CSharp{ class Program { public interface Subje

2014-09-27 12:49:41 314

原创 设计模式-策略模式

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CSharp{ class Program { public abstract class

2014-09-27 11:54:25 281

原创 设计模式-单例模式

#include #include using namespace std;class Single{public: Single (const Single &) = delete; Single &operator=(const Single&) = delete; static shared_ptr get_instance () { if (u

2014-09-24 01:35:47 277

原创 设计模式-装饰者模式

动态地将 #include #include //drinkclass Beverage{public: Beverage () = default; Beverage (string description_) :description (description_) {} virtual ~Beverage () = default; virt

2014-09-22 17:47:26 239

原创 设计模式: 观察者模式

#include #include #include using namespace std;class Observer{ friend class weather_data;public: Observer (size_t ID_) :ID (ID_) {} virtual ~Observer () = default;protected: si

2014-09-22 02:48:36 280

原创 Qt 与C11 对string 的处理

#include #include #include using namespace std;QTextStream cin(stdin, QIODevice::ReadOnly);QTextStream cout(stdout, QIODevice::WriteOnly);void display_data(char *buff, size_t len){

2014-09-20 16:27:50 681

原创 类型分类技术(type classification)

/* *设一个模版具有模版参数T, 表示C++ 中的某种类型 * 有些情况下随着T 的不同, 模版会做不同的处理 * 所以需要了解T 的具体信息 * * 我们可以用类型分类技术(type classification)提供T 的信息 * 我们将所被指的或被引用的类型命名为baseT * 将T 最终涉及的C++ 基本类型设为bot

2014-09-17 01:15:45 527

原创 Traits技术

/* *Traits技术以一个统一的编程接口描述各种数据类型的基本特征. * *例如float 的最大值为 2^128, 在float.h 中被定义为FLT_MAX_EXP * double 的最大值为 2^1024,被定义为DBL_MAX_EXP. * 此外, float 和double 的最小值也不同, 分别定义为 * FLT_EPS

2014-09-17 00:06:36 264

原创 设计模式: 策略模式

设有一基类Duck, 为

2014-09-16 02:01:23 309

原创 C++ 多线程入门1

#include #include using namespace std;struct my_thread{ my_thread (int i_) :i (i_) {} void operator()() { //do_something; }private: int i;};//using RAIIclass thread_gu

2014-09-14 19:38:00 340

原创 输出流的格式控制

//bool 值的格式 cout << "default bool format: " << true << " " << false << "\n" << "alpha bool values: " << boolalpha << true << " " << false << "\n" << "original bool format: " << noboolalpha <<

2014-09-07 19:03:13 342

原创 重载模板的顺序

重载 #include using namespace std;template void g (T t) { cout << "g(T)" << " "; } template void g (T *t) { cout << "g(T*)" << " "; } //匹配所有*p 实参, 即使是co

2014-09-05 18:33:24 319

原创 模版实参的推断和引用

//从左值引用函数参数推断类型//只能传左值, 若实参为const, 则推断为const 左值引用template void f1(T&);int i = 0;const int ci = i;f1(i); //T is intf1(ci); //T is const intf1(5); //error

2014-09-05 00:11:06 347

原创 Group By 的用法

using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Diagnostics;using System.IO;names

2014-09-03 15:29:41 410

原创 斐波那契数列规律的解释及实现

很多人都听说过斐波那契数列, 也知道它的规律, 但有些人

2014-09-03 01:57:09 987

原创 简单模版的使用

#include #include #include #include //accept an array, print it's elemstemplatevoid Print (const T (&array)[M]){ for (const auto &elem : array) cout << elem << "\n";}//accep

2014-09-01 07:43:20 255

原创 获取目标路径下所有文件名的枚举集合

using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Diagnostics;using System.IO;names

2014-08-26 18:26:58 551

原创 集合内的简单排序

using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Diagnostics;namespace Csharp{

2014-08-22 13:11:19 230

原创 求给定范围内素数

using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Diagnostics;namespace Csharp{

2014-08-20 17:00:12 422

原创 支持逻辑运算符的文本查询程序的OOP实现

#include #include #include #include #include #include #include #include #include using namespace std;//All of classes are pointerclass QueryResult{ friend ostream& p

2014-08-20 15:15:02 254

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除