fork(1) download
  1. class stack:
  2. def __init__(self,max_size):
  3. self.__max_size=max_size
  4. self.__elements=[None]*self.__max_size
  5. self.__top=-1
  6.  
  7. def is_full(self):
  8. if(self.__top==self.__max_size-1):
  9. return True
  10. return False
  11.  
  12. def is_empty(self):
  13. if(self.__top==-1):
  14. return True
  15. return False
  16.  
  17. def push(self, data):
  18. if(self.is_full()):
  19. print("The stack is full!!")
  20. else:
  21. self.__top+=1
  22. self.__elements[self.__top]=data
  23.  
  24. def pop(self):
  25. if(self.is_empty()):
  26. print("The stack is empty!!")
  27. else:
  28. data= self.__elements[self.__top]
  29. self.__top-=1
  30. return data
  31.  
  32. def display(self):
  33. if(self.is_empty()):
  34. print("The stack is empty")
  35. else:
  36. index=self.__top
  37. while(index>=0):
  38. print(self.__elements[index])
  39. index-=1
  40.  
  41. def get_max_size(self):
  42. return self.__max_size
  43.  
  44.  
  45. def function (input_stack):
  46. if input_stack.is_empty():
  47. return
  48. out_stack= stack(input_stack.get_max_size())
  49. value=1
  50. while (not input_stack.is_empty()):
  51. out_stack.push(input_stack.pop()*value)
  52. value+=1
  53. if (out_stack.pop()//value)<value:
  54. out_stack.push(out_stack.pop()*out_stack.pop())
  55. return out_stack
  56.  
  57. s=stack(10)
  58. s.push(5)
  59. s.push(2)
  60. s.push(7)
  61. s.push(10)
  62. s.push(3)
  63. s1=function(s)
  64. for i in range(3):
  65. print(s1.pop())
Success #stdin #stdout 0.02s 9228KB
stdin
Standard input is empty
stdout
168
20
3