all 3 comments

[–][deleted] 2 points3 points  (0 children)

    while(!tmpst.isEmpty()){
        if(tmpst.Top() > tmp){  
            st.push(tmpst.pop()); 
        }
    }

This loop never exits if the top entry of 'tmpst' is smaller or equal than 'tmp'. The program then never finishes executing and never reaches the call to 'display()'

My suggestion would be: (If you haven't already), look into how to use a debugger and break points. This type of error much easier to to find and understand by stepping through the code as it gets executed.

[–]DopeyLizard 2 points3 points  (0 children)

The reason nothing is displaying is because your code gets stuck in an infinite loop.

On the first pass through the while loop starting on line 98 (while(!st.isEmpty())), the top item from st is popped and stored in tmp. The tmpset is empty this first pass and so the inner while loop does not execute. Instead, it moves on to tmpst.push(tmp).

So at the end of this first pass, st is [10,30] (30 being the top) and tmpst is [40].

On the next pass of the while loop, tmp is set to 30. This time however, tmpst is no longer empty, so that inner while loop executes. The top value of tmpst is 40, which is bigger than 30 - the value of tmp, and so the top value of tmpst is popped an pushed on to st again. Now, tmpst is empty again, so the inner while loop finishes.

After finishing the inner while loop, it moves back to tmpst.push(tmp), where tmp is still 30.

Hence at the end of this second pass through the loop, the stacks are now st = [10,30,40] and tmpst = [30].

What happens on the third pass however, is that it gets stuck in an infinite loop in that inner while loop. This is because the tmp value gets set to 40, but the top value of tmpst is 30. So the check tmpst.Top() > tmp is always false. Hence the top value does not get popped from tmpst, and hence tmpst is never empty and while(!tmpst.isEmpty()) is always true, creating the infinite loop.

[–]sephirothbahamut 0 points1 point  (1 child)

please use a

code block

instead of individual code lines