Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit 3b4c7d1

Browse files
authored
added Reverse()
1 parent 6a92c7e commit 3b4c7d1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

consoleutilities.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,21 @@ namespace as {
9494
void ChangeColorText(Color colorID) {SetConsoleTextAttribute(h, colorID); }
9595
}
9696

97+
// Contains alogrithms.
9798
namespace alogrithm {
98-
// Coverts a binary string into a integer
99+
100+
// Reverses a string
101+
string Reverse(string& str) {
102+
int n = str.length();
103+
for (int i = 0; i < n / 2; i++)
104+
{
105+
swap(str[i], str[n - i - 1]);
106+
}
107+
108+
return str;
109+
}
110+
111+
// Converts binary into decimal
99112
int toBinary(string bin, int length)
100113
{
101114
int val = 1;

0 commit comments

Comments
 (0)