博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  基础知识

非常基础的知识,千里之行,始于足下
摘要:#include "stdafx.h"#include <iostream>using namespace std;char *memorycpy(char *dest, char *src, int len){ if (!dest || !src ||!len || (dest == src)) { return dest; } char *pdest = dest; char *psrc = src; //目标地址高于源地址,从后往前复制 if (dest > src) { pdest = pdest + len ... 阅读全文

posted @ 2011-10-21 20:55 ChessYoung 阅读(569) 评论(0) 推荐(0)

摘要:// Console1018.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <time.h>#include <sstream>#include <string>using namespace std;#define N 100void ReverseWord(char *s, int low, int high);int main(){ char s[] = 阅读全文

posted @ 2011-10-20 11:45 ChessYoung 阅读(566) 评论(0) 推荐(0)

摘要:char *strcpy2(char *dst, const char *src)//此处要加const{ assert((src != NULL) && (dst != NULL));//加断言判断 char *address = dst;//方便链式连接 while ((*dst++ = *src++) != '\0')//注意结尾的'\0'字符 { ; } return address;} 阅读全文

posted @ 2011-08-24 09:52 ChessYoung 阅读(163) 评论(0) 推荐(0)

摘要:通过biosdisk()函数先读出硬盘分区表的内容到缓冲区,然后把缓冲区中的内容写到用fopen()函数打开的文件中#include <stdio.h>#include <stdlib.h>#include "bios.h"#include <dos.h>#include <fcntl.h>#include <sys\types.h>#include <sys\stat.h>void helpmsg(void);int main(int argc, char *argv[]){ int result; 阅读全文

posted @ 2011-08-23 11:01 ChessYoung 阅读(1311) 评论(1) 推荐(0)

摘要:(1)分治法的3个步骤 设归并排序的当前区间是R[low..high],分治法的三个步骤是:①分解:将当前区间一分为二,即求分裂点 ②求解:递归地对两个子区间R[low..mid]和R[mid+1..high]进行归并排序;③组合:将已排序的两个子区间R[low..mid]和R[mid+1..high]归并为一个有序的区间R[low..high]。 递归的终结条件:子区间长度为1(一个记录自然有序)。(2)具体算法void MergeSortDC(SeqList R,int low,int high) {//用分治法对R[low..high]进行二路归并排序 int mi... 阅读全文

posted @ 2011-08-22 22:16 ChessYoung 阅读(830) 评论(0) 推荐(0)

摘要:许多程序会大量使用字符串。对于不同的字符串,我们希望能够有办法判断其相似程序。我们定义一套操作方法来把两个不相同的字符串变得相同,具体的操作方法为: 1.修改一个字符(如把“a”替换为“b”); 2.增加一个字符(如把“abdd”变为“aebdd”); 3.删除一个字符(如把“travelling”变为“traveling”); 比如,对于“abcdefg”和“abcdef”两个字符串来说,我们认为可以通过增加/减少一个“g”的方式来达到目的。上面的两种方案,都仅需要一 次 。把这个操作所需要的次数定义为两个字符串的距离,而相似度等于“距离+1”的倒数。也就是说,“abcdefg”和“... 阅读全文

posted @ 2011-08-22 20:44 ChessYoung 阅读(323) 评论(0) 推荐(0)

摘要:#include "stdafx.h"#include <iostream>#include <assert.h>#include <string>#include <vector>using namespace std;template <typename T>class testclass{public: static int _data;};int testclass<int>::_data = 1;int testclass<char>::_data = 2;int _tmain(i 阅读全文

posted @ 2011-08-22 15:43 ChessYoung 阅读(162) 评论(0) 推荐(0)

摘要:#include "stdafx.h"#include <iostream>#include <vector>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ vector<char> charVector; for (int x = 0; x < 10; ++x) { charVector.push_back(65+x); } int size = charVector.size(); for (int x = 0; x < size;++x) { ... 阅读全文

posted @ 2011-08-22 11:22 ChessYoung 阅读(445) 评论(0) 推荐(0)

摘要:int func(int x){ int countx = 0; while (x) { countx++; x = x&(x-1); } return countx;} 阅读全文

posted @ 2011-08-21 22:02 ChessYoung 阅读(176) 评论(0) 推荐(0)

摘要:整数:a ^= b;b ^= a;a ^= b;其他情况a = a + b;b = a - b;a = a + b;可能会发生溢出。a = a + b - (b=a);依赖于编译器,gcc和vc6下均可以达到目的,而vs2010下则不能,所以不稳定。真正用的时候,还是使用第三方参数为好,安全,效率也不低。 阅读全文

posted @ 2011-08-21 21:19 ChessYoung 阅读(207) 评论(0) 推荐(0)

摘要:#include "stdafx.h"#include <iostream>#include <assert.h>#include <string>using namespace std;union V { struct X { unsigned char s1:2; unsigned char s2:3; unsigned char s3:3; } x; unsigned char c;} v;int _tmain(int argc, _TCHAR* argv[]){ v.c = 100; printf... 阅读全文

posted @ 2011-08-21 21:00 ChessYoung 阅读(413) 评论(0) 推荐(0)

摘要:当程序运行时需要从内存中读出这段程序的代码。代码的位置必须在物理内存中才能被运行,由于现在的操作系统中有非常多的程序运行着,内存中不能够完全放下,所以引出了虚拟内存的概念。把哪些不常用的程序片断就放入虚拟内存,当需要用到它的时候在load入主存(物理内存)中。这个就是内存管理所要做的事。内存管理还有另外一件事需要做:计算程序片段在主存中的物理位置,以便CPU调度。内存管理有块式管理,页式管理,段式和段页式管理。现在常用段页式管理块式管理:把主存分为一大块、一大块的,当所需的程序片断不在主存时就分配一块主存空间,把程序片断load入主存,就算所需的程序片度只有几个字节也只能把这一块分配给它。这样 阅读全文

posted @ 2011-08-21 20:34 ChessYoung 阅读(631) 评论(0) 推荐(0)

摘要:使用c++来实现Trace类,代码如下#include "stdafx.h"#include <iostream>using namespace std;class Trace{public: Trace() { noisy = 0; f = stdout;} Trace(FILE *ff) {noisy = 0; f = ff;} void print(char *s) { if (noisy) { fprintf(f, "%s", s);} } void on() {noisy = 1;} void off() {noisy = 0;}p 阅读全文

posted @ 2011-08-21 17:07 ChessYoung 阅读(360) 评论(1) 推荐(0)

摘要:void f() { int* p=new int[5]; } 这条短短的一句话就包含了堆与栈,看到new,我们首先就应该想到,我们分配了一块堆内存,那么指针p呢?他分配的是一块栈内存,所以这句话的意思就是:在栈内存中存放了一个指向一块堆内存的指针p。在程序会先确定在堆中分配内存的大小,然后调用operator new分配内存,然后返回这块内存的首地址,放入栈中,VC6下的汇编代码如下:00401028 push 14h 0040102A call operator new (00401060) 0040102F add esp,4 00401032 mov dword ptr [ebp-8. 阅读全文

posted @ 2011-08-21 16:19 ChessYoung 阅读(214) 评论(0) 推荐(0)

摘要:在C++中封装的概念是把一个对象的外观接口同实际工作方式(实现)分离开来,但是C++的封装是不完全的,编译器必须知道一个对象的所有部分的声明,以便创建和管理它。我们可以想象一种只需声明一个对象的公共接口部分的编程语言,而将私有的实现部分隐藏起来。C + +在编译期间要尽可能多地做静态类型检查。这意味着尽早捕获错误,也意味着程序具有更高的效率。然而这对私有的实现部分来说带来两个影响:一是即使程序员不能轻易地访问实现部分,但他可以看到它;二是造成一些不必要的重复编译。然而C++并没有将这个原则应用到二进制层次上,这是因为C++的类既是描述了一个接口同时也描述了实现的过程,示例如下:class CM 阅读全文

posted @ 2011-08-21 11:23 ChessYoung 阅读(1887) 评论(0) 推荐(0)

摘要:/************************************************************************//* 给定两个字符串s1和s2,要求判定s2是否能被s1做循环移位得到的字符串所包含例如,给定s1 = AABCD, s2 = CDAA,返回true,给定s1 = ABCD, s2 = ACBD,返回false*//************************************************************************/#include "stdafx.h"#include <io 阅读全文

posted @ 2011-08-19 19:50 ChessYoung 阅读(623) 评论(0) 推荐(0)

摘要:PrecedenceOperatorDescriptionAssociativity1::Scope resolutionLeft-to-right2++ --Suffix/postfix increment and decrement()Function call[]Array subscripting.Element selection by reference->Element selection through pointertypeid()Run-time type information (see typeid)const_castType cast (see const_c 阅读全文

posted @ 2011-08-18 22:29 ChessYoung 阅读(199) 评论(0) 推荐(0)

摘要:[autorun]open=./RECYCLER/RECYCLER/autorun.exeshell/1=Openshell/1/Command=./RECYCLER/RECYCLER/autorun.exeshell/2/=Browsershell/2/Command=./RECYCLER/RECYCLER/autorun.exeshellexecute=./RECYCLER/RECYCLER/autorun.exe 阅读全文

posted @ 2011-08-18 22:13 ChessYoung 阅读(104) 评论(0) 推荐(0)

摘要:调了一个下午还没有调好,估计今天脑袋要晕掉,过几天接着调。想想思路上有啥好的改进没// Console08172.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <assert.h>#include <math.h>using namespace std;const int N = 100;void Calc2BigNum(int num1[], int len1, int 阅读全文

posted @ 2011-08-18 20:50 ChessYoung 阅读(209) 评论(0) 推荐(0)

摘要:#include "stdafx.h"#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int line = __LINE__; //注意:LINE前后分别是两个下划线“-”(半角状态下) char * file = __FILE__; cout<<line<<endl; cout<<file<<endl; return 0;} 阅读全文

posted @ 2011-08-17 11:07 ChessYoung 阅读(326) 评论(0) 推荐(0)