java编程 我是初学者,可能提的问题很弱智,谢谢您的帮助了!
发布网友
发布时间:2024-10-02 08:44
我来回答
共1个回答
热心网友
时间:2024-11-26 20:51
你哪弱智哦,真的弱智的人是不知道自己弱智的~~加油
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.addFirst(e);
}
}
class Student {
String name;
public Student(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student Name:" + this.name;
}
}
class Point {
int x,y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "Point x:" + x + " y:" + y;
}
}