您的位置:首页 > 其它

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

2015-10-11 12:09 393 查看
时间:2015.02.07

地点:软件大楼

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

[cpp] view
plaincopy





#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: