【百度】写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好

时间:2015.02.07

地点:软件大楼

1.写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好。

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include <stdio.h>  
  2. static void ReverseStr(char* str);  
  3. int main(void) {  
  4.     char arr[]="hello world";  
  5.     ReverseStr(arr);  
  6.     printf("the reverse result is: %s\n",arr);  
  7.     return 0;  
  8. }  
  9. void ReverseStr(char* str)  
  10. {  
  11.     char* head=str;  
  12.     char* tail=str;  
  13.     char temp;  
  14.     while(*tail!='\0')  
  15.     {  
  16.         tail++;  
  17.     }  
  18.     --tail;  
  19.     while(head<=tail)  
  20.     {  
  21.         temp=*head;  
  22.         *head=*tail;  
  23.         *tail=temp;  
  24.         ++head;  
  25.         --tail;  
  26.     }  
  27.     return;  
  28. }  



网址:http://blog.csdn.net/u012333003/article/details/43611487

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值