Skip to content

Commit 04b55b9

Browse files
committed
Reversing string using Stack
1 parent 8608038 commit 04b55b9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Stack/P04_ReverseString.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Author: OMKAR PATHAK
2+
3+
# Reverse a string using Stack
4+
5+
import Stack
6+
7+
def reverse(string):
8+
myStack = Stack.Stack(len(string))
9+
for i in string:
10+
myStack.push(i)
11+
12+
result = ''
13+
while not myStack.isEmpty():
14+
result += myStack.pop()
15+
16+
return result
17+
18+
if __name__ == '__main__':
19+
print(reverse('omkar'))

0 commit comments

Comments
 (0)