⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listitem.java

📁 Beginning Java 2, SDK 1.4 Edition Exercise Code samples for this book
💻 JAVA
字号:
// Chapter 6 Exercise 4

// Modified to support backwards traversal of the list.
// Additions and modifications are marked by ***.

public class ListItem {
  ListItem next;             // Refers to next item in the list.
  ListItem previous;         // Refers to the previous item.       ***
  Object item;               // The item for this ListItem.

  // Constructor: 
  public ListItem(Object item) {
    this.item = item;        // Store the item.
    next = previous = null;  // Set next and previous to null.      ***
  }

  // Set the pointer to the next ListItem:
  public void setNext(ListItem next) {
    this.next = next;        // Store reference to the next item.
  }
  
  // Additional method to set the pointer to the previous ListItem:  ***
  public void setPrevious(ListItem previous) {                                                               
    this.previous = previous; // Store reference to the previous item. 
  }
 
  // Get the next item in the list:
  public ListItem getNext() {
    return next;
  }

  // Additional method to get the previous item in the list:         ***
  public ListItem getPrevious() {
    return previous;
  }

  // Get the object for this item:
  public Object getObject() {
    return item;
  }

  // Return class name & object:
  public String toString() {
    return "ListItem " + item;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -