最近遇到或听说的面试笔试题
2012-09-25 17:51
309 查看
拓扑排序
http://www.cnblogs.com/xiaosuo/archive/2010/03/26/1690302.html
一个fork的面试题
http://coolshell.cn/articles/7965.html连续最大子序列
/article/1361451.htmlKMP字符串匹配算法 国外论文-
http://www.ics.uci.edu/~eppstein/161/960227.html字符串反转
原地逆序
char* Reverse(char* s) { // p指向字符串头部 char* p = s ; // q指向字符串尾部 char* q = s ; while( *q ) ++q ; q -- ; // 交换并移动指针,直到p和q交叉 while(q > p) { char t = *p ; *p++ = *q ; *q-- = t ; } return s ; }
不允许临时变量的逆序
// 使用异或操作对字符串s进行逆序 char* Reverse(char* s) { char* r = s ; //令p指向字符串最后一个字符 char* p = s; while (*(p + 1) != '\0') ++p ; // 使用异或操作进行交换 while (p > s) { *p = *p ^ *s ; *s = *p ^ *s ; *p = *p-- ^ *s++ ; } return r ; }
按单词逆序
给定一个字符串,按单词将该字符串逆序,比如给定"This is a sentence",则输出是"sentence a is This",为了简化问题,字符串中不包含标点符号。void ReverseWord(char* p, char* q) { while(p < q) { char t = *p ; *p++ = *q ; *q-- = t ; } } char* ReverseSentence(char *s) { char *p = s ; // point to the first char of a word char *q = s ; // point to a white space or '\0' while(*q != '\0') { if (*q == ' ') { ReverseWord(p, q - 1) ; q++ ; // move to next word p = q ; } else q++ ; } ReverseWord(p, q - 1) ; // Reverse the last word ReverseWord(s, q - 1) ; // Reverse the whole sentence return s ; }
以下是自己写的时候犯错误的方法,注意if 判断的条件不能随便调换,否则后果很严重
//错误的方法:先判断不是空格,因为'\0'也不是空格 void ReserveSentence1(char* s) { char* p=s; char* q=s; while(*q!='\0') { if(*q!=' ') { q++; } else { ReserveWord(p,q-1); q++; p=q; } } }
对于我这个菜鸟而言,在测试这些代码的时候,传参发生了错误,在此提醒一下自己
注意字符串的定义
void main() { char *str="I am a boy, I like YY"; //常量区域 char s[] = "I am a boy, I like YY"; //变量区域 char t[] = "I am a boy I like YY very much"; //变量区域 Reverse(s); //函数体不能改变常量区域的指针,我这个菜鸟一只犯错 //Reverse(str); 错误的传参 cout<<s<<endl; ReserveSentence(t); cout<<t<<endl; system("pause"); }
字符串相似度
http://www.cppblog.com/whncpp/archive/2008/09/21/62378.html随机数生成
http://blog.csdn.net/stone688598/article/details/6853989链表
struct LinkNode { int data; LinkNode* next; };
链表的反转
LinkNode* ReverseList(LinkNode* head) { LinkNode* pReverseHead=NULL; LinkNode* pNode=head; LinkNode* pPrev=NULL; LinkNode* next=NULL; while(pNode!=NULL) { next=pNode->next; if(next==NULL) pReverseHead=pNode; pNode->next=pPrev; pPrev=pNode; pNode=next; } return pReverseHead; }
把链表的构造给忘记了。。。。。。。。。。。。。。。好好检讨一下
有序链表合并
LinkNode* Merge(LinkNode* pHead1,LinkNode* pHead2) { if(pHead1==NULL) return pHead2; if(pHead2==NULL) return pHead1; LinkNode* pMergeHead=NULL; if(pHead1->data>pHead2->data) { pMergeHead=pHead1; pMergeHead->next=Merge(pHead1->next,pHead2); } else { pMergeHead=pHead2; pMergeHead->next=Merge(pHead1,pHead2->next); } return pMergeHead; }
相关文章推荐
- 最近遇到或听说的面试笔试题
- 最近遇到的一些笔试面试题目(持续更新中。。)
- 总结一下最近面试遇到的一些问题吧
- 笔试面试中遇到的一些智力题总结和思考,欢迎补充和指正
- 【最近面试遇到的一些问题】多线程有几种实现方法,都是什么?同步有几种实现方法,都是什么
- 某语音软件公司面试遇到的三个笔试题小结
- 最近遇到的几个c++笔试题
- 笔试和面试中遇到的问题(1)
- 最近的面试笔试题总结
- 【算法】 最近面试遇到的一道报数出队列的题
- sql去重问题(最近java笔试总遇到这个问题,忍不住要记录一下)
- 【最近面试遇到的一些问题】forward 和redirect的区别
- 最近面试笔试的经验
- java基础:常见的概念问题,面试笔试可能会遇到哟
- 最近Java面试遇到的快排
- 【最近面试遇到的一些问题】JSP中动态INCLUDE与静态INCLUDE的区别
- 面试中遇到的一些笔试题
- 嵌入式面试中遇到几道笔试题
- 【最近面试遇到的一些问题】数据库连接池的优点和原理,常用的java开源连接池组件
- 最近的一些笔试面试网站和书籍