-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.cpp
More file actions
42 lines (37 loc) · 700 Bytes
/
reverse.cpp
File metadata and controls
42 lines (37 loc) · 700 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
/**
* @file reverse.cpp
* @author Abhishek
* @brief Reversing the string from bothe directions technique:
* complexityO(n/2)-> O(n)
* @version 0.1
* @date 2022-04-25
*
* @copyright Copyright (c) 2022
*
*/
#include <iostream>
void reverse(char *str)
{
int count = 0;
for(int i = 0; str[i] != '\0'; i++)
{
count++;
}
for(int i = 0,j = count-1; i < j; i++,j--)
{
char temp = ' ';
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
for(int i = 0; str[i] != '\0'; i++)
{
std::cout << str[i];
}
}
int main(int argc, char const *argv[])
{
char str[] = "Abhishek";
reverse(str);
return 0;
}