write a program to implement reversal of a string using stack data structure in list of numbers
class Stack:
def __init__(self):
self.list = []
def add(self, value):
self.list.append(value)
def pop(self):
if self.list:
return self.list.pop()
string = input()
stack1 = Stack()
for ch in string:
stack1.add(ch)
reversed_string = ''
ch = stack1.pop()
while ch:
reversed_string += ch
ch = stack1.pop()
print(reversed_string)
Comments
Leave a comment