java编程 我是初学者,可能提的问题很弱智,谢谢您的帮助了!

来源:百度知道 编辑:UC知道 时间:2024/09/22 09:35:06
根据数据结构的知识编写一个栈的类,利用它产生两个对象,分别以栈的形式存储Student类的对象,和Point类的对象。编写测试类。

你哪弱智哦,真的弱智的人是不知道自己弱智的~~加油

import java.util.*;

public class Test1 {
public static void main (String args[]) {
MyStack<Student> s1 = new MyStack<Student>();
MyStack<Point> s2 = new MyStack<Point>();

s1.push(new Student("小明1"));
s1.push(new Student("小强2"));
s1.push(new Student("小狗3"));
s2.push(new Point(7,7));
s2.push(new Point(7,8));
s2.push(new Point(7,9));

System.out.println(s1.pop());
System.out.println(s1.pop());
System.out.println(s1.pop());

System.out.println(s2.pop());
System.out.println(s2.pop());
System.out.println(s2.pop());
}
}

class MyStack<T> {
LinkedList<T> list = new LinkedList<T>();

public T pop() {
return this.list.removeFirst();

}

public void push(T e) {
this.list.add