def createStack(): stack=[] return stack def size(stack): return len(stack) def isEmpty(stack): if size(stack) == 0: return true def push(stack,item): stack.append(item) def pop(stack): if isEmpty(stack): return return stack.pop() def reverse(string): n = len(string) stack = createStack() for i in range(0,n,1): push(stack,string[i]) for i in range(0,n,1): string+=pop(stack) return string s = "ello-mlher-sup" print ("real string : ",end="") print (s) print ("reversed string(using stack) is : ",end="") print (reverse(s))
Log in or sign up for Devpost to join the conversation.