-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReverseString.cpp
41 lines (31 loc) · 889 Bytes
/
ReverseString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* \file ReverseString.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
template<typename T >
void
reverseString(T &a)
{
const std::size_t _size = a.size();
for (typename T::size_type i = 0; i < (_size / 2); ++ i) {
const std::size_t index1 = i;
const std::size_t index2 = (_size - 1) - i;
std::swap(a[index1], a[index2]);
}
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::string str = "54321";
::reverseString(str);
std::cout << STD_TRACE_VAR(str) << std::endl;
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
str: gfedcba
#endif