小编vvv*_*vvv的帖子

插入到栈尾

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) …

java recursion return

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

recursion ×1

return ×1