代码改变世界

vs 2008调试错误

2009-10-10 19:15 by Iron, 327 阅读, 0 推荐, 收藏, 编辑
摘要:今天用vs2008打开以往做的一个练习,使用断点调试时,死活对应不上,该停的地方不停,不该停的地方莫名其妙的停下,我还以为我发现vs 2008的bug了,突然想到,是不是源文件的编码出错了,用txt打开,改成ansi果然恢复正常。只是我一直没有动过编码,怎么会有这种错误呢。。。 阅读全文

约瑟夫环问题

2009-10-09 20:07 by Iron, 213 阅读, 0 推荐, 收藏, 编辑
摘要:用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。写出C程序。采用循环列表,先将所有的节点加载进来,而后每数到一个,输出数据后,删除数据#include <iostream>#include <vector>using namespace std;class Node{public: Node *pre; Node *next; int data... 阅读全文

将字符串转为数字

2009-10-09 15:39 by Iron, 202 阅读, 0 推荐, 收藏, 编辑
摘要:#include <cstdio>#include <cassert>int atoi(const char* str){ assert(str!=NULL); const char* s = str; int value=0; while(*s!='\0') { value *= 10; value += *s - '0'; s++; } return value;... 阅读全文

逆置单链表

2009-10-09 14:37 by Iron, 193 阅读, 0 推荐, 收藏, 编辑
摘要:主要使用三个指针,作为辅助,具体算法简单易懂,大家看一下程序就知道了#include using namespace std;class Node{public: int data; Node *next; Node(int d) { this->data = d; this->next = NULL; } Node* Reverse() { Node* p= NULL; No... 阅读全文

C实现strcmp

2009-10-09 11:29 by Iron, 833 阅读, 0 推荐, 收藏, 编辑
摘要:比较简单就不说了,只是提醒路过的朋友,注意函数的各种情况及返回条件#include <cstdio>int strcmpEx(const char * sa, const char * sb){ const char* stra = sa; const char* strb = sb; while(*stra!='\0'&&*strb!='\0') { if (*st... 阅读全文

查询字符串在指定字符串中出现的次数

2009-10-09 11:12 by Iron, 820 阅读, 0 推荐, 收藏, 编辑
摘要:思路:遍历指定字符串,找到和字符串有相同开始的位置,然后逐个比对,比对完成后,接着对指定字符串做查找操作#include <cstdio>#include <cstring>int CountOfsubstr(const char* src,char* substr){ int count = 0; const char* s = src; int len = strlen... 阅读全文

字符串移位

2009-10-08 21:15 by Iron, 254 阅读, 0 推荐, 收藏, 编辑
摘要:思路:对于"abcdef",如果右移两位,则先将"abcd"反向为"dcba",然后将"ef"反向为"fe",然后再最后整个字符串反向一次,变成"efabcd"程序代码如下:#include <cstdio>#include <cassert>#include <cstring>void Reverse(char *str, int start,int end)... 阅读全文

百度面试题字符串筛选

2009-10-07 17:49 by Iron, 272 阅读, 0 推荐, 收藏, 编辑
摘要:题目:实现 void delete_char(char * str, char ch); 把str中所有的ch删掉解析:最容易想到的算法是遍历字符串,找到目标,删掉后对后面的元素进行移位,这样算法的复杂度是O(n^2),不是最优方法,我下面的方法的复杂度为O(n),是线性时间,实现如下#include <cstdio>#include <cstring>void delet... 阅读全文

内存对齐的经典算法

2009-10-06 17:08 by Iron, 505 阅读, 0 推荐, 收藏, 编辑
摘要:原文地址http://bbs.chinaunix.net/viewthread.php?tid=814501此文太过经典,不得不转问:#define _INTSIZEOF(n) ((sizeof(n)+sizeof(int)-1)&~(sizeof(int) - 1) )说能够在某些系统中内存对齐.(估计是得到一个2 或者4的整数倍)这个好象就是(x+3)&~3这样就能满足对齐了吗... 阅读全文

Template argument deduction (C++ only)

2009-10-06 14:12 by Iron, 805 阅读, 0 推荐, 收藏, 编辑
摘要:Thanks:http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/template_argument_deduction.htmWhen you call a template function, you may omit any tem... 阅读全文
上一页 1 2 3 4 5 6 ··· 21 下一页