Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Reverse an string Using Stack in Python

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])
string=""
for i in range(0,n,1):
string+=pop(stack)
return string
s = "SoftHunt"
print ("The original string is : ",end="")
print (s)
print ("The reversed string(using stack) is : ",end="")
print (reverse(s))
Comment

PREVIOUS NEXT
Code Example
Python :: ordenar lista python 
Python :: Python Tkinter RadioButton Widget 
Python :: python if elif else 
Python :: pytest logcli to write to file 
Python :: specific mail.search python UNSEEN SINCE T 
Python :: run a python script from another python script on a raspberry pi 
Python :: concat dataframe pandas 
Python :: replace characters in string python 
Python :: python replace n with actual new line 
Python :: run multiple test cases pytest 
Python :: pandas lambda applu 
Python :: create a window using tkinter 
Python :: pandas dataframe add two columns int and string 
Python :: Python - How To Count Occurrences of a Character in a String 
Python :: defaultdict initialize keys 
Python :: remove file os python 
Python :: pyton do while loop+ 
Python :: matplotlib draw line x1, y1 
Python :: how to fix def multiply(a ,b): a*b 
Python :: pandas df describe() 
Python :: python is space 
Python :: how to redirect user in flask response python 
Python :: python includes string 
Python :: socket programming python 
Python :: mount gdrive in pyton 
Python :: numpy reshape 
Python :: drop 0 in np array 
Python :: flat numpy array 
Python :: string upper lower count python 
Python :: properties of tuples in python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =