1

2008年4月21日

判断一个单向链表是否有环,算法证明

摘要: 判断一个单向链表是否有环:给定链表的头指针:list *head。步长法:intlooplist(list*head){list*p,*q;if(head==NULL){return0;}p=head;q=head;while((p->next!=NULL)&&(q->next!=NULL)&&(q->next->next!=NULL)){p... 阅读全文

posted @ 2008-04-21 21:34 清水无鱼 阅读(4022) 评论(1) 推荐(0)

回调机制

摘要: 回调顾名思义,被调用方反过来调用调用方。c/c++中用函数指针来实现:voidfuntion(intx,inty){……}voidcaller(void(*fp)(intx,inty)){……}voidmain(){   void(*fp)(intx,inty);   inta=10,b=20;   fun=function;   caller(fu... 阅读全文

posted @ 2008-04-21 21:08 清水无鱼 阅读(297) 评论(0) 推荐(0)

C++ volatile

摘要: 变量定义为volatile,说明这变量可能会被意想不到地改变。比如下面的程序:longmultiple(volatileint*pt){return(*pt)*(*pt);}代码告诉编译器 *pt (而非pt)的值可能在其他地方被改变。所以程序运行中,每次读取*pt时,即便在高速缓存中命中,也要都要到内存中重新读取。上述 (*pt)*(*pt)其实是读了两次*pt, 因此两次读到的值可能不一致,所... 阅读全文

posted @ 2008-04-21 17:27 清水无鱼 阅读(495) 评论(0) 推荐(0)

C++ c# 分别实现单件模式

摘要: C# 1)publicsealedclassSingleton{staticSingletoninstance=null;privateSingleton(){}publicstaticSingletonInstance{get{if(instance==null){instance=newSingleton();}returninstance;}}}2) 线程安全publicsealedclas... 阅读全文

posted @ 2008-04-21 16:49 清水无鱼 阅读(1173) 评论(1) 推荐(0)

内存模型

摘要: C++: 代码区 全局数据区 堆区 栈区 C# 堆区 栈区 阅读全文

posted @ 2008-04-21 16:14 清水无鱼 阅读(140) 评论(0) 推荐(1)

struct vs class

摘要: C++:在C++中struct和class只有一个区别:struct默认public, 而class默认private.C#:1) struct valueType, classs refType.结构体对象在分配在堆栈上,而不是托管堆上。(当结构中含有引用成员时,堆栈中保存引用,引用指向的实际内容分配在堆中)2) struct 不允许程序员自定义默认构造函数。如果定义构造函数,则必须初始化所有字... 阅读全文

posted @ 2008-04-21 16:09 清水无鱼 阅读(246) 评论(0) 推荐(0)

C++ sizeof

摘要: 1. sizeof(char) =   1                          2. sizeof 'a' =   1                         3. sizeof "a" =    2                    4. strlen("a") = 2short (*ptr[100])[200]; 1. sizeof(ptr) = 100*sizeof... 阅读全文

posted @ 2008-04-21 15:45 清水无鱼 阅读(174) 评论(0) 推荐(0)

c++ const 修饰指针

摘要: const 用于指针的情况分析: 1) int const *A;  //A可变,*A不可变,A只能赋予const int 型变量的地址。 int a=10; A=&a //错误 2) int *const A;  //A不可变,*A可变 inta=10; int *const A=&a;//正确const int b=10; int *const A=&b;//错误3) ... 阅读全文

posted @ 2008-04-21 15:22 清水无鱼 阅读(169) 评论(0) 推荐(0)

C++ const static

摘要: C++: 代码区 全局数据区 堆区 栈区 修饰全局和局部变量时: 修饰全局变量:static 作用域是整个文件,其值保存在全局静态存储区域中。 修饰局部变量:static 初始化一次,下次调用将跳过初始化,其作用是函数块,存储在静态存储区域中。修饰类成员时: static 类级别, const对象级别。 const只能在构造函数参数列表中赋值。 const 可修饰类成员函数,使得函数不能修改对象状... 阅读全文

posted @ 2008-04-21 15:20 清水无鱼 阅读(452) 评论(0) 推荐(0)

c# readonly vs const

摘要: c# readonly vs const 阅读全文

posted @ 2008-04-21 14:44 清水无鱼 阅读(752) 评论(0) 推荐(0)

1

导航