c面试题库.docx
- 文档编号:8741828
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:7
- 大小:14.92KB
c面试题库.docx
《c面试题库.docx》由会员分享,可在线阅读,更多相关《c面试题库.docx(7页珍藏版)》请在冰豆网上搜索。
c面试题库
c面试题库
1、实现strcmp
intStrCmp(constchar*str1,constchar*str2)
做是做对了,没有抄搞,比较乱
intStrCmp(constchar*str1,constchar*str2)
{
assert(str1srt2);
while(*str1*str2*str1==*str2){
str1++,str2++;
}
if(*str1*str2)
return(*str1-*str2);
elseif(*str1*str2==0)
return1;
elseif(*str1==0*str2)
return-1;
else
return0;
}
intStrCmp(constchar*str1,constchar*str2)
{
//省略判断空指针(自己保证)
while(*str1*str1++==*str2++);
return*str1-*str2;
}
2、实现子串定位
intFindSubStr(constchar*MainStr,constchar*SubStr)
做是做对了,没有抄搞,比较乱
intMyStrstr(constchar*MainStr,constchar*SubStr)
{
constchar*p;
constchar*q;
constchar*u=MainStr;
//assert((MainStr!
=NULL)(SubStr!
=NULL));//用断言对输入进行判断
while(*MainStr)//内部进行递增
{
p=MainStr;
q=SubStr;
while(*q*p*p++==*q++);
if(!
*q)
{
returnMainStr-u+1;//MainStr指向当前起始位,u指向
}
MainStr++;
}
return-1;
}
3、已知一个单向链表的头,请写出删除其某一个结点的算法,要求,先找到此结点,然后删除。
slnodetype*Delete(slnodetype*Head,intkey){}中if(Head-number==key)
{
Head=Pointer-next;
free(Pointer);
break;
}
Back=Pointer;
Pointer=Pointer-next;
if(Pointer-number==key)
{
Back-next=Pointer-next;
free(Pointer);
break;
}
voiddelete(Node*p)
{
if(Head=Node)
while(p)
}
4、有1,2,....一直到n的无序数组,求排序算法,并且要求时间复杂度为O(n),空间复杂度O
(1),使用交换,而且一次只能交换两个数.(华为)
#includeiostream.h
intmain()
{
inta[]={10,6,9,5,2,8,4,7,1,3};
intlen=sizeof(a)/sizeof(int);
inttemp;
for(inti=0;ilen;)
{
temp=a[a[i]-1];
a[a[i]-1]=a[i];
a[i]=temp;
if(a[i]==i+1)
i++;
}
for(intj=0;jlen;j++)
couta[j],
return0;
}
5、写出程序把一个链表中的接点顺序倒排
typedefstructlinknode
{
intdata;
structlinknode*next;
}node;
//将一个链表逆置
node*reverse(node*head)
{
node*p,*q,*r;
p=head;
q=p-next;
while(q!
=NULL)
{
r=q-next;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面试 题库