棧中元素的彈出
棧中的彈出操作是指從棧中刪除元素。在對棧執行此操作時,將刪除棧頂的元素,即最後插入棧的元素將首先彈出。(後進先出)
示例
import java.util.Stack;
public class PoppingElements {
public static void main(String args[]) {
Stack stack = new Stack();
stack.push(455);
stack.push(555);
stack.push(655);
stack.push(755);
stack.push(855);
stack.push(955);
System.out.println("Elements of the stack are :"+stack.pop());
System.out.println("Contents of the stack after popping the element :"+stack);
}
}
輸出
Elements of the stack are :955 Contents of the stack after popping the element :[455, 555, 655, 755, 855]
廣告