/* DListNode1.java */
public class DListNode1 {
public Object item;
// public short[][] colorVal;
public DListNode1 prev;
public DListNode1 next;
DListNode1() {
item = 0;
prev = null;
next = null;
}
DListNode1(Object i) {
item = i;
prev = null;
next = null;
}
}
/* Double linked list */
public class DList1 {
protected DListNode1 head;
protected DListNode1 tail;
protected long size;
public DList1() {
head = null;
tail = null;
size = 0;
}
public DList1(Object a) {
head = new DListNode1();
tail = head;
head.item = a;
size = 1;
}
public DList1(Object a, Object b) {
head = new DListNode1();
head.item = a;
tail = new DListNode1();
tail.item = b;
head.next = tail;
tail.prev = head;
size = 2;
}
public void insertFront(Object i) {
DListNode1 temp = new DListNode1(i);
if (size == 0) {
head = temp;
tail = temp;
}
else {
temp.next = head;
head.prev = temp;
head = temp;
} size++;
}
public void removeFront() {
if (size == 0) {
return;
}
else if (size == 1) {
head = null;
tail = null;
size--;
}
else {
head = head.next;
head.prev = null;
size--;
}
}
public String toString() {
String result = "[ ";
DListNode1 current = head;
while (current != null) {
result = result + current.item + " ";
current = current.next;
}
return result + "]";
}
public class num{
public int j;
public num() {
this.j = 34;
}
}
public class testing{
private DList1 dli;
private num n;
public testing(){
dli = new DList1();
n = new num();
dli.insertFront(n);}
public static void main(String[] args) {
testing Jimmy = new testing();
System.out.printf(" this should be 34 %d\n",Jimmy.dli.head.item.j);// dont' work.
}
}
谁能告诉我为什么我不能做Jimmy.dli.head.item.j
?它非常有意义,但它说“j不能解决或不是领域”。如何修复它以便打印34
?没有这一行“dli.insertFront(n.j);”传递对象到DLIST
反正谁是'吉米'? o.O – Smutje
'item'的类型是'Object','Object'没有名为'j'的字段 –
item是正确的?不是n.j = 34? – user3331457