-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayBagTest.java
More file actions
35 lines (27 loc) · 1.23 KB
/
ArrayBagTest.java
File metadata and controls
35 lines (27 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bagPrograms;
public class ArrayBagTest {
public static void main(String[] args) {
// This ArrayBagTest.java file is extremely similar to the LinkedbagTest.java, just different layouts
// The content used in the bags
String[] contentsOfbag1 = { "a", "b", "c", "c", "b", "a" };
String[] contentsOfbag2 = {"w", "v", "b", "c",};
// Creates the resizeable array bags
BagInterface<String> bag1 = new ResizableArrayBag<>(contentsOfbag1);
BagInterface<String> bag2 = new ResizableArrayBag<>(contentsOfbag2);
// Calls the union and intersection method, and then moves the result to the union and intersection arrays respectively
BagInterface<String> everything = bag1.union(bag2);
BagInterface<String> commonItems = bag1.intersection(bag2);
Object[] bagArrayUnion = everything.toArray();
Object[] bagArrayIntersection = commonItems.toArray();
// Outputs results
System.out.print("Array Union: ");
for (int i = 0; i < everything.getCurrentSize(); i++) {
System.out.print(bagArrayUnion[i]);
}
System.out.println(" ");
System.out.print("Array Intersection: ");
for (int i = 0; i < commonItems.getCurrentSize(); i++) {
System.out.print(bagArrayIntersection[i]);
}
}
}