0

我有一个 add 方法,它将最新的文本字符串插入到我希望它作为第一个文本字符串插入的列表的末尾。任何帮助表示赞赏。这是方法:

 public void add (Magazine mag)
  {

  MagazineNode node = new MagazineNode (mag);
  MagazineNode current;

  if (list == null)
     list = node;
  else
  {
     current = list;
     while (current.next != null)
        current = current.next;
     current.next = node;
  }
   }
4

2 回答 2

4

假设我了解您需要,这可能会关闭,我认为您需要以下方法。

public void add_first (Magazine mag)
{
  MagazineNode node = new MagazineNode (mag);

  // make the new first node point to the current root
  node.next=list;

  // update the root to the new first node
  list=node;
}
于 2012-11-27T03:50:12.920 回答
0
public void add (Magazine mag)
{
  MagazineNode node = new MagazineNode (mag);    
  node.next = list;
  list = node;
}
于 2012-11-27T03:49:48.820 回答