0
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);
}
}
在上面的代碼的末尾插入,我有一個關於這一步的問題:在堆棧
if(st.isEmpty())
st.push(x);
難道我們需要st.push(x)
後return語句?
我的意思是說,在遞歸堆棧中,當條件滿足時,即堆棧爲空時,它會將x推入堆棧,但是如何返回前一個沒有返回語句的調用?
這是什麼語言? – melpomene
Java語言它是 – vijay
推是最後的聲明,因爲只有'if'語句的'else'部分如下。所以它在呼叫站點返回。 –