MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / add

Method add

src/main/java/com/thealgorithms/datastructures/bags/Bag.java:61–67  ·  view source on GitHub ↗

Adds an element to the bag. This method adds the specified element to the bag. Duplicates are allowed, and the bag will maintain the order in which elements are added. @param element the element to add; must not be null

(E element)

Source from the content-addressed store, hash-verified

59 * @param element the element to add; must not be {@code null}
60 */
61 public void add(E element) {
62 Node<E> newNode = new Node<>();
63 newNode.content = element;
64 newNode.nextElement = firstElement;
65 firstElement = newNode;
66 size++;
67 }
68
69 /**
70 * Checks if the bag contains a specific element.

Callers 15

testBagOperationsMethod · 0.95
testAddElementsMethod · 0.95
testContainsMethodMethod · 0.95
testIteratorMethod · 0.95
testMixedTypeElementsMethod · 0.95

Calls

no outgoing calls

Tested by 15

testBagOperationsMethod · 0.76
testAddElementsMethod · 0.76
testContainsMethodMethod · 0.76
testIteratorMethod · 0.76
testMixedTypeElementsMethod · 0.76