Answer to Question #267714 in Python for Ram

Question #267714

write a program to implement reversal of a string using stack data structure in list of numbers

1
Expert's answer
2021-11-19T10:02:35-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS