class LinListProg {
public static void main (String [] args) {
try {
LinList ptr = new LinList (args[0]);
int i = 1;
while (i < args.length) {
ptr.insert(args[i]);
i++;
}
ptr.print();
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println ("Maybe you did not gave the necessary number of arguments");
}
}
static class LinList {
LinList next;
LinList prev;
String val;
LinList (String val) {
this.next = null;
this.prev = null;
this.val = val;
}
void insert (String val) {
LinList new_ptr = new LinList (val);
LinList ptr = this;
LinList prev_ptr = this;
while (ptr != null) {
prev_ptr = ptr;
ptr = ptr.next;
}
prev_ptr.next = new_ptr;
new_ptr.next = null;
new_ptr.prev = prev_ptr;
}
void print () {
LinList ptr = this;
while (ptr != null) {
System.out.println (ptr.val);
ptr = ptr.next;
}
}
}
}