-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
75 lines (54 loc) · 2.06 KB
/
Main.java
File metadata and controls
75 lines (54 loc) · 2.06 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package set;
public class Main {
public static void main(String[] args) {
SortedLinkedSetTest();
SortedArraySetTest();
}
public static void SortedLinkedSetTest() {
SortedLinkedSet<Integer> s1 = new SortedLinkedSet<>();
for(int x : new int[]{3, 7, 2, 1, 3, 4})
s1.insert(x);
System.out.println("s1: "+s1);
SortedLinkedSet<Integer> s2 = new SortedLinkedSet<>();
for(int x : new int[]{0, 3, 5, 4, 1, 8})
s2.insert(x);
System.out.println("s2: "+s2);
s2.delete(1);
s2.delete(10);
System.out.println("s2 after deletes: "+s2);
SortedLinkedSet<Integer> s3 = SortedLinkedSet.union(s1, s2);
System.out.println("s3: "+s3);
SortedLinkedSet<Integer> s1Copy = new SortedLinkedSet<>(s1);
System.out.println("s1Copy: "+s1Copy);
s1Copy.union(s2);
System.out.println("s1Copy after union: "+s1Copy);
SortedLinkedSet<Integer> s4 = SortedLinkedSet.intersection(s1, s2);
System.out.println("s4: "+s4);
SortedLinkedSet<Integer> s5 = SortedLinkedSet.difference(s1, s2);
System.out.println("s5: "+s5);
System.out.println();
}
public static void SortedArraySetTest() {
SortedArraySet<Integer> s1 = new SortedArraySet<>();
for(int x : new int[]{3, 7, 2, 1, 3, 4})
s1.insert(x);
System.out.println("s1: "+s1);
SortedArraySet<Integer> s2 = new SortedArraySet<>();
for(int x : new int[]{0, 3, 5, 4, 1, 8})
s2.insert(x);
System.out.println("s2: "+s2);
s2.delete(1);
s2.delete(10);
System.out.println("s2 after deletes: "+s2);
SortedArraySet<Integer> s3 = SortedArraySet.union(s1, s2);
System.out.println("s3: "+s3);
SortedArraySet<Integer> s1Copy = new SortedArraySet<>(s1);
System.out.println("s1Copy: "+s1Copy);
// s1Copy.union(s2);
// System.out.println("s1Copy after union: "+s1Copy);
SortedArraySet<Integer> s4 = SortedArraySet.intersection(s1, s2);
System.out.println("s4: "+s4);
SortedArraySet<Integer> s5 = SortedArraySet.difference(s1, s2);
System.out.println("s5: "+s5);
System.out.println(); }
}