how to reverse the word sequence in a sentence?

For example, "Welcome you to Beijing" is reversed into "Beijing to you Welcome"

void ReverseString(char *s, int start, int end)
 2{
 3    while (start < end)
 4    {
 5        if (s[start] != s[end])
 6        {
 7            s[start] ^= s[end];
 8            s[end] ^= s[start];
 9            s[start] ^= s[end];
10        }
11                
12        start++;
13        end--;
14    }
15}
16
17
void ReverseByWords(char *s, int len, char seperator)
{
19    int start = 0, end = 0;
20
21    ReverseString(s, start, len - 1);
22
23    while (end < len)
24    {
25        if (s[end] != seperator)
26        {
27            start = end;
28
29            while (end < len && s[end] != seperator)
30                end++;
31            end--;
32
33            ReverseString(s, start, end);
34        }
        
          end++;

          }//while
} 

 

 

你可能感兴趣的:(sequence)