-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path20 Stack reverse string.cpp
More file actions
85 lines (72 loc) · 1.21 KB
/
20 Stack reverse string.cpp
File metadata and controls
85 lines (72 loc) · 1.21 KB
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
75
76
77
78
79
80
81
82
83
84
85
/*
Write a program to reverse the string using stack.
Input Format
Enter a string.
Constraints
Maximum size of string is 30 and minimum size is 5
Output Format
Display reverse of given string
Sample Input 0
Programming practice
Sample Output 0
ecitcarp gnimmargorP
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct s1
{
char d1;
s1 *next =NULL;
s1 * pre=NULL;
};
s1 *top1=NULL,*p1=NULL;
void push1(char item)
{
if(top1==NULL)
{
top1 = new s1;
top1->d1=item;
}
else
{
p1 =new s1;
p1->d1=item;
p1->pre=top1;
top1->next=p1;
top1 = p1;
}
}
int pop1()
{
char deleted;
{
deleted = top1->d1;
if(top1->pre==NULL)
top1=NULL;
else
{
top1 = top1->pre;
top1->next=NULL;
}
return deleted;
}
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
string s;
getline(cin, s);
for(int i=0;i<s.length();i++)
{
push1(s[i]);
}
while(top1!=NULL)
{
cout<<top1->d1;
pop1();
}
return 0;
}