【百度】写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好
2015-10-11 12:09
393 查看
时间:2015.02.07
地点:软件大楼
1.写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好。
[cpp] view
plaincopy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
#include <stdio.h>
static void ReverseStr(char* str);
int main(void) {
char arr[]="hello world";
ReverseStr(arr);
printf("the reverse result is: %s\n",arr);
return 0;
}
void ReverseStr(char* str)
{
char* head=str;
char* tail=str;
char temp;
while(*tail!='\0')
{
tail++;
}
--tail;
while(head<=tail)
{
temp=*head;
*head=*tail;
*tail=temp;
++head;
--tail;
}
return;
}
网址:http://blog.csdn.net/u012333003/article/details/43611487
地点:软件大楼
1.写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好。
[cpp] view
plaincopy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
#include <stdio.h>
static void ReverseStr(char* str);
int main(void) {
char arr[]="hello world";
ReverseStr(arr);
printf("the reverse result is: %s\n",arr);
return 0;
}
void ReverseStr(char* str)
{
char* head=str;
char* tail=str;
char temp;
while(*tail!='\0')
{
tail++;
}
--tail;
while(head<=tail)
{
temp=*head;
*head=*tail;
*tail=temp;
++head;
--tail;
}
return;
}
网址:http://blog.csdn.net/u012333003/article/details/43611487
相关文章推荐
- Leetcode--Best Time to Buy and Sell Stock III
- Some Life Tricks I Noticed
- TCP/IP、Http、Socket的区别
- 2016联想校招图形图像软件工程师在线笔试真题
- HDOJ 题目1576 A/B(拓展欧几里得求乘法逆元)
- 【人工智能】农夫过河问题
- POJ-2039
- HDU5501/BestCoder Round #59 (div.2)The Highest Mark dp+贪心
- C#使用基类的引用 and 虚方法和覆写方法
- 定时自动启动任务crontab命令用法
- 条件编译(#ifdef #else #endif #if)
- C#内存管理-栈堆/回收器托管/非托管资源释放/指针的应用
- 【小白装系统】——U盘法简介
- BZOJ 1061: [Noi2008]志愿者招募(最小费用最大流)
- 分西瓜(DFS)
- iOS_Quartz 2D绘图
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- win 10 右键新建offic失效问题
- iOS 视频播放基础
- 服 务 器 时 间 设 置