static void insert_at_bottom(char x){
if(st.isEmpty())
st.push(x);
else{
/* All items are held in Function Call Stack until we
reach end of the stack. When the stack becomes
empty, the st.size() becomes 0, the
above if part is executed and the item is inserted
at the bottom */
char a = st.peek();
st.pop();
insert_at_bottom(x);
//push all the items held in Function Call Stack
//once the item is inserted at the bottom
st.push(a);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我对这一步有一个疑问:
if(st.isEmpty())
st.push(x);
Run Code Online (Sandbox Code Playgroud)
之后我们不需要 return 语句吗st.push(x) …