Created
June 24, 2020 06:18
-
-
Save ahmadmustafaanis/545a1334f9ae15a3dcb2508af07200c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <stack> | |
using namespace std; | |
class InduvivualWordsReverser { | |
private: | |
string h1; | |
stack < char > s1; | |
public: | |
InduvivualWordsReverser() { | |
h1 = ""; | |
} | |
void init(string); | |
string reverseInduviuval(); | |
}; | |
void InduvivualWordsReverser::init(string a1) | |
{ | |
h1 = a1; | |
} | |
string InduvivualWordsReverser::reverseInduviuval() | |
{ | |
string reversedString = ""; | |
for (int i = 0; i < h1.length(); i++) | |
{ | |
if (h1[i] == ' ') | |
{ | |
while (!(s1.empty())) | |
{ | |
reversedString += s1.top(); | |
s1.pop(); | |
} | |
reversedString += ' '; | |
} | |
else | |
{ | |
s1.push(h1[i]); | |
} | |
} | |
while (!(s1.empty())) | |
{ | |
reversedString += s1.top(); | |
s1.pop(); | |
} | |
reversedString += ' '; | |
return reversedString; | |
} | |
int main() | |
{ | |
InduvivualWordsReverser h1; | |
h1.init("Geeks for Geeks"); | |
string rev = h1.reverseInduviuval(); | |
cout << rev; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment