forked from priyanka090700/hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringrev_Stack.py
More file actions
37 lines (26 loc) · 710 Bytes
/
stringrev_Stack.py
File metadata and controls
37 lines (26 loc) · 710 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
from collections import deque
stack = deque()
class Stack:
def __init__(self):
self.container = deque()
def push(self, val):
self.container.append(val)
def pop(self):
return self.container.pop()
def peek(self):
return self.container[-1]
def is_empty(self):
return len(self.container) == 0
def size(self):
return len(self.container)
def reverse_string(string_here):
stack = Stack()
rev = ""
for ch in string_here:
stack.push(ch)
while not stack.is_empty():
rev += stack.pop()
return rev
if __name__ == "__main__":
string_data = "reverse this String"
print(reverse_string(string_data))