Aritalab:Lecture/Programming/Java/Graph/LinkedList

From Metabolomics.JP
Jump to: navigation, search

二重リンクリストの構造のみ

class LinkedList
  {
    protected ListEntry listHead = null;

    protected ListEntry listTail = null;

    protected int listSize = 0;

    protected LinkedList()
      {}

    protected void remove(ListEntry x)
      {
        ListEntry x_succ = x.succ;
        ListEntry x_pred = x.pred;

        if (x_succ != null)
          {
            x_succ.pred = x_pred;
            x.succ = null;
          }
        else
          listTail = x_pred;

        if (x_pred != null)
          {
            x_pred.succ = x_succ;
            x.pred = null;
          }
        else
          listHead = x_succ;

        listSize--;
      }

    public ListEntry head()
      {
        return listHead;
      }

    public ListEntry tail()
      {
        return listTail;
      }

    public ListEntry Pred(ListEntry e)
      {
        return e.pred;
      }

    public ListEntry Succ(ListEntry e)
      {
        return e.succ;
      }

    public void clear()
      {
        listHead = null;
        listTail = null;
        listSize = 0;
      }

    public int size()
      {
        return listSize;
      }

    public boolean empty()
      {
        return (listSize == 0) ? true : false;
      }
  }
Personal tools
Namespaces

Variants
Actions
Navigation
metabolites
Toolbox