class IntList {
final static int PLAIN = 0;
final static int EXTENDED = 1;
IntCell first;
IntCell last;
IntList(IntCell f, IntCell l) {
first = f;
last = l;
}
// Transform an array of integers into
// a doubly-linked list of integers.
public static IntList array2intList(int[] i) {
for (int j=0; j<i.length; j++) {
IntCell = new IntCell(null, i[j], null);
}
return null;
}
****More stuff should be here that is irrelevant i've just taken out***
// Pretty Print a doubly-linked list.
// Views: * PLAIN, e.g. [ 3, 4, 5 ]
// * EXTENDED, includes all references
public void printIntList(int view) {
if (view == EXTENDED) {
System.out.print("FIRST: ");
System.out.println(first);
System.out.print("LAST: ");
System.out.println(last);
System.out.println();
}
IntCell next = this.first;
boolean start = true;
if (view == PLAIN) {
System.out.print("[ ");
}
while (next != null) {
if (view == EXTENDED) {
next.printIntCell();
} else {
if (!start) {
System.out.print(", ");
}
System.out.print(next.contents);
}
start = false;
next = next.successor;
}
if (view == PLAIN) {
System.out.println(" ]");
}
}
}
package LinkedLists;
class IntCell {
int contents;
IntCell predecessor;
IntCell successor;
IntCell(int i) {
contents = i;
predecessor = null;
successor = null;
}
IntCell(IntCell p, int i, IntCell s) {
contents = i;
predecessor = p;
successor = s;
}
public void printIntCell() {
System.out.print(contents);
System.out.print(" : ( ");
System.out.print(predecessor);
System.out.print(" ) <---p--- ( ");
System.out.print(this);
System.out.print(" ) ---s---> ( ");
System.out.print(successor);
System.out.println(" )");
}
}