
程序员面试宝典
zhiy_wis
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
约瑟夫环问题
/** *约瑟夫环:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围。 *从编号为k的人开始报数,数到m的那个人出列; *他的下一个人又从1开始报数,数到m的那个人又出列; *依此规律重复下去,直到圆桌周围的人全部出列。 *实现方式:循环链表 *2013-10-15 **/ #include #include using namespace std; typedef struc原创 2013-10-15 09:26:55 · 1005 阅读 · 0 评论 -
隐式类型转换
1、混合类型的算术表达式中 在这种情况下最宽的数据类型成为目标转换类型----算术转换 int ival = 3; double dval = 3.14159; //ival被提升为double类型:3.0 ival + dval 2、用一种类型的表达式赋值给另一种类型的对象 在这种情况下目标转换类型是被赋值对象的类型 // 0 被转换成int*类型的空指针值 int *pi = 0; //原创 2013-10-15 09:30:36 · 912 阅读 · 0 评论 -
sizeof 与strlen区别
1、 sizeof是运算符,strlen是函数 2、 sizeof可以用类型做参数,strlen只能用char*做参数,且必须是以“\0”结尾的。 3、 大部分编译程序在编译的时候就把sizeof计算过了,是类型或是变量的长度;strlen的结果要在运行的时候才能计算出来,用来计算字符串的长度,而不是类型占内存的大小 char str[20]=”0123456789”; int a=strle原创 2013-10-15 09:34:10 · 813 阅读 · 0 评论 -
给出一个单链表,不知道节点N的值,怎样只遍历一次就可以求出中间节点,写出算法。
算法:设立两个指针,比如*p和*q,p每次移动两个位置,即p=p->next->next,q每次移动一个位置,即q=q->next。当p到达最后一个节点时,q就是中间节点了。 void searchmid(node* head,node* mid) { node *temp=head; while(head->next->next != NULL) { head = head->nex原创 2013-10-15 09:35:47 · 2797 阅读 · 1 评论 -
冒泡、插入、希尔和快速排序算法
#define MAXN 7 #include using namespace std; int a[MAXN] = {4,3,2,1,5,9,6}; //交换 void swap(int &a,int &b) { int tmp; if(a > b) { tmp = a; a = b; b = tmp; } } //输出 void show() { int i; for原创 2013-10-19 14:50:13 · 832 阅读 · 0 评论 -
不调用字符串库函数,实现字符串复制函数
#include #include #include void stringcpy(char *to,const char *from) { assert(to != NULL && from != NULL); while(*from != '\0') *to++ = *from++; *to = '\0'; } int main() { char *f; char *t; f原创 2013-10-21 10:05:23 · 1613 阅读 · 0 评论 -
字符子串问题
转换字符串格式为原来字符串里的字符+该字符连续出现的个数 /** *input:1233544 *output:1121325142 **/ #include #include using namespace std; int main() { cout<<"Enter the numbers:"<<endl; string str; char reschar[50]; rescha原创 2013-10-21 11:06:56 · 844 阅读 · 0 评论