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

2011年10月21日

摘要: #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 阅读(558) 评论(0) 推荐(0) 编辑

2011年10月20日

摘要: // 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 阅读(558) 评论(0) 推荐(0) 编辑

2011年8月24日

摘要: 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 阅读(157) 评论(0) 推荐(0) 编辑

2011年8月23日

摘要: 通过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 阅读(1247) 评论(1) 推荐(0) 编辑

2011年8月22日

摘要: (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 阅读(782) 评论(0) 推荐(0) 编辑

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

posted @ 2011-08-22 20:44 ChessYoung 阅读(308) 评论(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 阅读(156) 评论(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 阅读(402) 评论(0) 推荐(0) 编辑

2011年8月21日

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

posted @ 2011-08-21 22:02 ChessYoung 阅读(167) 评论(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 阅读(204) 评论(0) 推荐(0) 编辑