java有人能帮我理解这段代码是如何工作的吗?这是课堂上的一个例子,我想更有效地学习
编写代码,将10个字符串压入堆栈(版本2),边打印边删除
import java.math.*;
public class StackTest {
public static void main (String[] args){
Stack2 stk = new Stack2("Stack");
for(int i = 0; i < 10; i++){
stk.push("Item: " + (i + 1));
System.out.println("Pushing: Item: " + (i + 1));
}
System.out.println("\n" + stk.print());
for(int i = 0; i < 10; i++){
System.out.println("Popping: " + stk.pop());
}
System.out.println("\n" + stk.print());
}
}
# 1 楼答案
您拥有的是一个TestClass,用于测试堆栈的自定义实现
关于堆栈,您需要了解的一些关键问题是:
后进先出(后进先出)数据结构
这在浏览器中使用。当你点击后退按钮时
带您进入您访问的最后一页
您的控制台将显示如下内容: