Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. void str_reverse(char* str)
  2. {
  3.   static char* head;
  4.   char* tail;
  5.   char tmp;
  6.   if (!head)
  7.     head = str;
  8.   if (*str)
  9.     str_reverse(str + 1);
  10.   if (!head)
  11.     return;
  12.   tail = str - 1;
  13.   if (tail <= head) {
  14.     head = 0;
  15.     return;
  16.   }
  17.   tmp = *head;
  18.   *head = *tail;
  19.   *tail = tmp;
  20.   head++;
  21. }
  22.  
  23. int main()
  24. {
  25.   char s[] = "hello";
  26.   //char s[] = "hell";
  27.   //char s[] = "";
  28.   str_reverse(s);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement