I have changed the data type of my variables to long but I am still getting run time error.
Run time error in histogram
Use inbuilt stack instead of your own stack. After that you will get wrong answer. Check whether you have properly incremented the value of i or not . When you push the element in stack then only u have to increment the value of i.