c面试题库.docx

上传人:b****6 文档编号:8741828 上传时间:2023-02-01 格式:DOCX 页数:7 大小:14.92KB
下载 相关 举报
c面试题库.docx_第1页
第1页 / 共7页
c面试题库.docx_第2页
第2页 / 共7页
c面试题库.docx_第3页
第3页 / 共7页
c面试题库.docx_第4页
第4页 / 共7页
c面试题库.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

c面试题库.docx

《c面试题库.docx》由会员分享,可在线阅读,更多相关《c面试题库.docx(7页珍藏版)》请在冰豆网上搜索。

c面试题库.docx

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;

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1