Java 实例 - 获取链表的元素
Java 教程
· 2019-02-11 12:58:07
以下实例演示了使用 top() 和 pop() 方法来获取链表的元素:
Main.java 文件
import java.util.*;
public class Main {
private LinkedList list = new LinkedList();
public void push(Object v) {
list.addFirst(v);
}
public Object top() {
return list.getFirst();
}
public Object pop() {
return list.removeFirst();
}
public static void main(String[] args) {
Main stack = new Main();
for (int i = 30; i < 40; i++)
stack.push(new Integer(i));
System.out.println(stack.top());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
}
}
以上代码运行输出结果为:
39 39 38 37
点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html
XML Hacks
Michael Fitzgerald / O'Reilly Media, Inc. / 2004-07-27 / USD 24.95
Developers and system administrators alike are uncovering the true power of XML, the Extensible Markup Language that enables data to be sent over the Internet from one computer platform to another or ......一起来看看 《XML Hacks》 这本书的介绍吧!