-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReverse.cpp
47 lines (40 loc) · 822 Bytes
/
Reverse.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
42
43
44
45
46
47
#include <stdio.h>
#include <string.h>
#include "Const.h"
#include "Stack.h"
#include "Reverse.h"
int Reverse( char* string )
{
int nLen = 0;
char *pBegin = 0, *pEnd = 0;
char nState = 0;
// if string is NULL Situation, it is avoid ERROR Situation.
if( string == NULL )
{
fprintf(stderr, "Error: this String Argument is NULL.\n");
return FALSE;
}
nLen = (int) strlen( string );
pBegin = string;
pEnd = string + nLen;
// Push string.
while( pBegin <= pEnd )
{
nState = Push( *pBegin );
if( nState == FALSE )
break;
pBegin++;
}
// I needed Reinitialize pBegin Point Variable.
pBegin = string;
// and Pop string.
// As a result, return reversed string.
while( Underflowed() == FALSE )
{
nState = Pop();
if( nState == FALSE )
break;
*(pBegin++) = nState;
}
return TRUE;
}