from os import *
from sys import *
from collections import *
from math import *
def is_empty(stack):
return len(stack)==0
def push(stack,item):
stack.append(item)
def pop(stack):
return stack.pop()
def top(stack):
return stack[-1]
#now we have to create function to place the elements in proper sorted order
def insert_sorted(stack,element):
#case 1 if the stack is empty or the top of the stack is less then or equal to the element
if is_empty(stack) or top(stack)<=element:
#than we have to push that element in the stack
push(stack,element)
else:
#the element is smaller than the top of stack
temp=pop(stack)
insert_sorted(stack,element)
push(stack,temp)
def sortStack(stack):
if not is_empty(stack):
temp=pop(stack)
sortStack(stack)
insert_sorted(stack,temp)