public class IntTreeBag
extends java.lang.Object
implements java.lang.Cloneable
IntTreeBag
is a collection of int numbers.
Limitations:
Beyond Integer.MAX_VALUE
elements, countOccurrences
,
and size
are wrong.
Outline of Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/collections/IntTreeBag.java
Note:
This file contains only blank implementations ("stubs")
because this is a Programming Project for my students.IntArrayBag
,
IntLinkedBag
Constructor and Description |
---|
IntTreeBag() |
Modifier and Type | Method and Description |
---|---|
void |
add(int element)
Insert a new element into this bag.
|
void |
addAll(IntTreeBag addend)
Add the contents of another bag to this bag.
|
java.lang.Object |
clone()
Generate a copy of this bag.
|
int |
countOccurrences(int target)
Accessor method to count the number of occurrences of a particular element
in this bag.
|
int |
size()
Determine the number of elements in this bag.
|
static IntTreeBag |
union(IntTreeBag b1,
IntTreeBag b2)
Create a new bag that contains all the elements from two other bags.
|
public void add(int element)
element
- the new element that is being inserted
Postcondition:
A new copy of the element has been added to this bag.java.lang.OutOfMemoryError
- Indicates insufficient memory a new IntBTNode.public void addAll(IntTreeBag addend)
addend
- a bag whose contents will be added to this bag
Precondition:
The parameter, addend
, is not null.
Postcondition:
The elements from addend
have been added to this bag.java.lang.IllegalArgumentException
- Indicates that addend
is null.java.lang.OutOfMemoryError
- Indicates insufficient memory to increase the size of the bag.public java.lang.Object clone()
clone
in class java.lang.Object
IntTreeBag
before it can be used.java.lang.OutOfMemoryError
- Indicates insufficient memory for creating the clone.public int countOccurrences(int target)
target
- the element that needs to be countedtarget
occurs in this bagpublic int size()
public static IntTreeBag union(IntTreeBag b1, IntTreeBag b2)
b1
- the first of two bagsb2
- the second of two bags
Precondition:
Neither b1 nor b2 is null.java.lang.IllegalArgumentException
- Indicates that one of the arguments is null.java.lang.OutOfMemoryError
- Indicates insufficient memory for the new bag.