class ParamLinListProg {
public static void main (String [] args) {
try {
int i;
ParamLinList <String> lst = new ParamLinList <String> (args[0]);
for (i = 1; i < args.length; i++)
lst.put (args[i]);
for (i = 0; i < args.length; i++) {
System.out.println (lst.getfirst());
lst.rm();
}
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println ("Usage: java ParamLinListProg data1 data2 ...");
}
}
public static class ParamLinList <P> {
P v;
ParamLinList next;
ParamLinList prev;
ParamLinList (P v) {
this.v = v;
this.next = this;
this.prev = this;
}
void put (P v) {
if ((this.v != null) && ((this.next != this) && (this.prev != this))) {
ParamLinList <P> ptr;
ptr = new ParamLinList <P> (v);
ptr.next = this;
ptr.prev = this.prev;
this.prev.next = ptr;
this.next.prev = ptr;
}
else
this.v = v;
}
P getfirst () {
return this.v;
}
P rm () {
if ((this.next != this) && (this.prev != this)) {
ParamLinList <P> ptr = this.next;
this.next.prev = this;
this.next = this.next.next;
return ptr.v;
}
else {
this.v = null;
return v;
}
}
}
}