华为C语言面试题

上传人:汽*** 文档编号:561402153 上传时间:2022-10-24 格式:DOC 页数:37 大小:566KB
返回 下载 相关 举报
华为C语言面试题_第1页
第1页 / 共37页
华为C语言面试题_第2页
第2页 / 共37页
华为C语言面试题_第3页
第3页 / 共37页
华为C语言面试题_第4页
第4页 / 共37页
华为C语言面试题_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《华为C语言面试题》由会员分享,可在线阅读,更多相关《华为C语言面试题(37页珍藏版)》请在金锄头文库上搜索。

1、 华为C语言经典面试题。每道题都附有详细解答和讲解。怎么判断链表中是否有环?bool CircleInList(Link* pHead)if(pHead = = NULL | pHead-next = = NULL)/无节点或只有一个节点并且无自环return (false);if(pHead-next = = pHead)/自环return (true);Link *pTemp1 = pHead;/step 1Link *pTemp = pHead-next;/step 2while(pTemp != pTemp1 & pTemp != NULL & pTemp-next != NULL)p

2、Temp1 = pTemp1-next;pTemp = pTemp-next-next;if(pTemp = = pTemp1)return (true);return (false);两个字符串,s,t;把t字符串插入到s字符串中,s字符串有足够的空间存放t字符串void insert(char *s, char *t, int i)memcpy(&sstrlen(t)+i,&si,strlen(s)-i);memcpy(&si,t,strlen(t);sstrlen(s)+strlen(t)=0;1。编写一个 C 函数,该函数在一个字符串中找到可能的最长的子字符串,且该字符串是由同一字符组

3、成的。char * search(char *cpSource, char ch)char *cpTemp=NULL, *cpDest=NULL;int iTemp, iCount=0;while(*cpSource)if(*cpSource = ch)iTemp = 0;cpTemp = cpSource;while(*cpSource = ch)+iTemp, +cpSource;if(iTemp iCount)iCount = iTemp, cpDest = cpTemp;if(!*cpSource)break;+cpSource;return cpDest;2。请编写一个 C 函数,该

4、函数在给定的存区域搜索给定的字符,并返回该字符所在位置索引值。int search(char *cpSource, int n, char ch)int i;for(i=0; ireturn i;一个单向链表,不知道头节点,一个指针指向其中的一个节点,问如何删除这个指针指向的节点?将这个指针指向的next节点值copy到本节点,将next指向next-next,并随后删除原next指向的节点。#includevoid foo(int m, int n)printf(m=%d, n=%dn, m, n);int main()int b = 3;foo(b+=3, +b);printf(b=%dn

5、, b);return 0;输出:m=7,n=4,b=7(VC6.0)这种方式和编译器中得函数调用关系相关即先后入栈顺序。不过不同编译器得处理不同。也是因为C标准中对这种方式说明为未定义,所以各个编译器厂商都有自己得理解,所以最后产生得结果完全不同。因为这样,所以遇见这种函数,我们首先要考虑我们得编译器会如何处理这样得函数,其次看函数得调用方式,不同得调用方式,可能产生不同得结果。最后是看编译器优化。2.写一函数,实现删除字符串str1中含有的字符串str2.第二个就是利用一个KMP匹配算法找到str2然后删除(用链表实现的话,便捷于数组)/Author: azhen#include#incl

6、ude#includechar *commanstring(char shortstring, char longstring)int i, j;char *substring=malloc(256);if(strstr(longstring, shortstring)!=NULL) /如果,那么返回shortstringreturn shortstring;for(i=strlen(shortstring)-1;i0; i-) /否则,开始循环计算for(j=0; jstrlen(str2) /将短的字符串放前面comman=commanstring(str2, str1);elsecomm

7、an=commanstring(str1, str2);printf(the longest comman string is: %sn, comman);11.写一个函数比较两个字符串str1和str2的大小,若相等返回0,若str1大于str2返回1,若str1小于str2返回1int strcmp ( const char * src,const char * dst)int ret = 0 ;while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) & *dst)+src;+dst;if ( ret 0 )ret =

8、1 ;return( ret );3,求1000!的未尾有几个0(用素数相乘的方法来做,如72=2*2*2*3*3);求出1-1000里,能被5整除的数的个数n1,能被25整除的数的个数n2,能被125整除的数的个数n3,能被625整除的数的个数n4.1000!末尾的零的个数=n1+n2+n3+n4;#include#define NUM 1000int find5(int num)int ret=0;while(num%5=0)num/=5;ret+;return ret;int main()int result=0;int i;for(i=5;idata = Value)if (pNode

9、-front = NULL)pHeader = pNode-next;pHeader-front = NULL;elseif (pNode-next != NULL)pNode-next-front = pNode-front;pNode-front-next = pNode-next;Node *pNextNode = pNode-next;delete pNode;pNode = pNextNode;bRet = TRUE;/不要break或return, 删除所有elsepNode = pNode-next;return bRet;void DE(Node *pHeadA, Node *

10、pHeadB)if (pHeadA = NULL | pHeadB = NULL)return;Node *pNode = pHeadA;while (pNode != NULL)if (DeteleNode(pHeadB, pNode-data)if (pNode-front = NULL)pHeadA = pNode-next;pHeadA-front = NULL;elsepNode-front-next = pNode-next;if (pNode-next != NULL)pNode-next-front = pNode-front;Node *pNextNode = pNode-next;delete pNode;pNode = pNextNode;elsepNode = pNode-next;2. 编程实现:找出两个字符串中最大公共子字符串,如abccade,dgcadde的最大子串为cadint GetCommon(char *s1, char *s2, char *r1, char *r2)int len1 = strlen(s1);int len2 = strlen(s2);int maxlen = 0;for(

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 模板/表格 > 财务表格

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号