/* author by w3cschool.cc 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 实例 - 获取链表的元素的内容。