-
Notifications
You must be signed in to change notification settings - Fork 0
/
reversestring.h
60 lines (48 loc) · 1.3 KB
/
reversestring.h
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
//============================================================================
// Name : test4.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <stdlib.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
int main() {
string holder;
queue<char> qholder;
queue<char> qholder2;
stack<char> sholder;
cout << "please enter the string you wish to reverse" << endl;
cin >> holder;
int y = holder.length();
cout << "!!!the string is : " << holder << endl; // prints !!!Hello World!!!
//cout <<holder[4]<<"!!!Hello!!!" << y <<endl;
for (int k = 0; k < y; k++) {
qholder.push(holder[k]);
// cout<<" The queued letter :"<<qholder.back();
}
cout << endl;
while (!qholder.empty()) {
sholder.push(qholder.front());
// cout<<qholder.front();
qholder.pop();
//cout<< " The top of the stack is "<<sholder.top();
}
cout << endl;
while (!sholder.empty()) {
//cout<<sholder.top();
qholder.push(sholder.top());
sholder.pop();
}
for (int k = 0; k < y; k++) {
holder[k] = qholder.front();
qholder.pop();
//cout<< k<< endl;
}
cout << " The reversed string is " << holder;
return 0;
}