Practical - 14 - Reverse A String Using Stack
Practical - 14 - Reverse A String Using Stack
class Node:
def __init__(self,data):
self.data = data
self.next = None
class Stack:
def __init__(self):
self.top = None
def is_empty(self):
def push(self,data):
new_node = Node(data)
if self.top is None:
self.top = new_node
else:
new_node.next = self.top
self.top=new_node
if not self.is_empty():
temp = self.top.data
self.top = self.top.next
return temp
# Creating a stack
st = Stack()
#String reversal
for ch in str:
st.push(ch)
rlist=[]
rlist.append(st.pop())
rstr=''.join(rlist)