时间:2015.02.07
地点:软件大楼
1.写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好。
- #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