forked from sinagarajan/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers.cpp
More file actions
74 lines (66 loc) · 949 Bytes
/
pointers.cpp
File metadata and controls
74 lines (66 loc) · 949 Bytes
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# include <iostream>
using namespace std;
int stringLength(char *value)
{
int length=0;
while(*(value+length)!='\0')
length++;
return length;
}
void stringReverse(char* value,int length)
{
char temp,*front,*last;
int itr=0;
front=value;
last=value;
while(itr<length-1)
{
last++;
itr++;
}
while(front<last)
{
temp=*front;
*front=*last;
*last=temp;
++front;
--last;
}
}
void stringPartreverse(char *begin,char *end)
{
char temp;
while(begin<end)
{
temp=*begin;
*begin=*end;
*end=temp;
begin++;end--;
}
}
void wordReverse(char *value)
{
char *itr=value;
char *front=value;
while(*itr)
{
itr++;
if((*itr )==' ')
{
stringPartreverse(front,itr-1);
front=itr+1;
}
else if((*itr)=='\0')
{
stringPartreverse(front,itr-1);
}
}
int length=stringLength(value);
stringReverse(value,length);
}
int main()
{
char sample[]="siva is my name";
wordReverse(sample);
cout<<sample;
}