类 ResizingArrayBag<Item>

  • 所有已实现的接口:
    java.lang.Iterable<Item>

    public class ResizingArrayBag<Item>
    extends java.lang.Object
    implements java.lang.Iterable<Item>
    The ResizingArrayBag class represents a bag (or multiset) of generic items. It supports insertion and iterating over the items in arbitrary order.

    This implementation uses a resizing array. See LinkedBag for a version that uses a singly linked list. The add operation takes constant amortized time; the isEmpty, and size operations take constant time. Iteration takes time proportional to the number of items.

    For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      ResizingArrayBag()
      Initializes an empty bag.
    • 方法概要

      修饰符和类型 方法 说明
      void add​(Item item)
      Adds the item to this bag.
      boolean isEmpty()
      Is this bag empty?
      java.util.Iterator<Item> iterator()
      Returns an iterator that iterates over the items in the bag in arbitrary order.
      static void main​(java.lang.String[] args)
      Unit tests the ResizingArrayBag data type.
      int size()
      Returns the number of items in this bag.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • 从接口继承的方法 java.lang.Iterable

        forEach, spliterator
    • 构造器详细资料

      • ResizingArrayBag

        public ResizingArrayBag()
        Initializes an empty bag.
    • 方法详细资料

      • isEmpty

        public boolean isEmpty()
        Is this bag empty?
        返回:
        true if this bag is empty; false otherwise
      • size

        public int size()
        Returns the number of items in this bag.
        返回:
        the number of items in this bag
      • add

        public void add​(Item item)
        Adds the item to this bag.
        参数:
        item - the item to add to this bag
      • iterator

        public java.util.Iterator<Item> iterator()
        Returns an iterator that iterates over the items in the bag in arbitrary order.
        指定者:
        iterator 在接口中 java.lang.Iterable<Item>
        返回:
        an iterator that iterates over the items in the bag in arbitrary order
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the ResizingArrayBag data type.
        参数:
        args - the command-line arguments