public class List_manager<E> {
Entry<E> first;
Entry<E> last;
public void add(E element) {
Entry<E> e=new Entry(element,last);
if (first==null) first=last;
}
public E get() {
Entry<E> temp=first;
first=first.next;
return temp.data;
}
public boolean isEmpty() { return first==null; }
private static class Entry<E> {
Entry<E> next;
E data;
public Entry(E element,Entry<E> to) {
data=element;
next=to;
to=this;
}
}
}
//now the main class
Trying to make a linkedlist
public class Main {
public static void main(String[] args) {
Point p1=new Point(0,0); //
Point p2=new Point(12,5);
Point p3=new Point(43,12);
List_manager<Point> l=new List_manager<Point>();
l.add(p1);
l.add(p2);
l.add(p3);
System.out.println(l.get()); // here is an error occurs
System.out.println(l.get());
}
}
// Point
Just a simple point
public class Point {
double x;
double y;
public Point(double x,double y) {
this.x=x;
this.y=y;
}
public String toString() {
return "("+Double.toString(x) + " , " + Double.toString(y) + ")";
}
}