human
Sort string of characters using Stack | function to print the characters in sorted order.
primary stack.
secondary stack.
append first character.
iterate for all character in string.
i - th character ASCII.
stack 's top element ASCII.
if greater or equal to top element then push to stack.
if smaller , then push all element to the temporary stack.
push all greater elements.
push operation.
push till the stack is not - empty.
push the i - th character.
push the tempstack back to stack.
print the stack in reverse order.
Driver Code"
Solution in Python:
assistant
#Here is code to sort string of characters using Stack and the other steps required.
 def printSorted ( s , l ) :
	stack = [ ]
	tempstack = [ ]
	stack . append ( s [ 0 ] )
	for i in range ( 1 , l ) :
		a = ord ( s [ i ] )
		b = ord ( stack [ - 1 ] )
		if ( ( a - b ) >= 1 or ( a == b ) ) :
			stack . append ( s [ i ] )
		elif ( ( b - a ) >= 1 ) :
			while ( ( b - a ) >= 1 ) :
				tempstack . append ( stack . pop ( ) )
				if ( len ( stack ) > 0 ) :
					b = ord ( stack [ - 1 ] )
				else :
					break
			stack . append ( s [ i ] )
			while ( len ( tempstack ) > 0 ) :
				stack . append ( tempstack . pop ( ) )
	print ( ' ' . join ( stack ) )
s = " geeksforgeeks "
l = len ( s )
printSorted ( s , l )