Skip to content

Commit e13ef31

Browse files
committed
disjoint sets
1 parent 7009db0 commit e13ef31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+508
-134
lines changed

Lab12/.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/Lab12.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/codeStyles/Project.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/codeStyles/codeStyleConfig.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab12/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
-620 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-1.38 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Lab12/src/TreeTwoThreeFour/Tree234.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import BST.BST;
44

5+
56
import java.util.ArrayList;
67

78
public class Tree234 {

Lab12/src/main2.java

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import RBTree.BlackRedTree;
33
import TreeTwoThreeFour.Tree234;
44

5-
import java.math.RoundingMode;
65
import java.util.ArrayList;
7-
import java.util.Arrays;
86

97
public class main2 {
108

Lab12/src/zad1/ArrayDisjoint.java

-23
This file was deleted.

Lab12/src/zad1/ArrayDisjointSetsNoCompression.java

-37
This file was deleted.

Lab12/src/zad1/main.java

+21-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package zad1;
22

3+
import zad1.onArrays.ArrayDisjoint;
4+
import zad1.onArrays.ArrayDisjointSetsCompression;
5+
import zad1.onArrays.ArrayDisjointSetsNoCompression;
6+
import zad1.onTrees.ForestDisjointSetCompression;
7+
import zad1.onTrees.ForestDisjointSetStabilization;
8+
import zad1.onTrees.ForestDisjontSet;
9+
10+
311
import java.util.ArrayList;
412

513
public class main {
@@ -23,6 +31,10 @@ public static void main(String[] args) {
2331
set2.union(4,5);
2432
set2.union(5,6);
2533
set2.union(6,7);// [0,1,2,3], [4,5,6,7], [8], [9]
34+
System.out.println("SET1");
35+
set1.displaySets();
36+
System.out.println("SET2");
37+
set2.displaySets();
2638

2739
System.out.println("Reprezentant [Czas szukania w nano sekundach]");
2840
System.out.println("Kompresja ścieżek dokłada kodu więc wtedy czas jest dłuższy");
@@ -43,50 +55,18 @@ public static void main(String[] args) {
4355

4456
System.out.println("Sets on forest");
4557

46-
ForestDisjointTreesSets forest = new ForestDisjointTreesSets(10);
47-
for (int i = 0; i < 10; i++) {
48-
forest.makeSet(i);
49-
}
50-
51-
for (int i = 0; i < 10; i+=2) {
52-
forest.union(i, i+1);
53-
}
54-
55-
displaySets(forest);
56-
System.out.println("1<->2");
57-
forest.union(1,2);
58-
displaySets(forest);
59-
System.out.println("2<->5");
60-
forest.union(2,5);
61-
displaySets(forest);
62-
System.out.println("9<->6");
63-
forest.union(9,6);
64-
displaySets(forest);
65-
}
66-
67-
public static void displaySets(ForestDisjointTreesSets forest){
68-
ArrayList<ArrayList<Integer>> sets = new ArrayList<>();
58+
ForestDisjontSet f1 = new ForestDisjointSetCompression(31);
59+
ForestDisjontSet f2 = new ForestDisjointSetStabilization(31);
6960

70-
for (int i = 0; i < 10; i++) {
71-
sets.add(new ArrayList<>());
61+
for (int i = 0; i < 30; i+=2) {
62+
f1.union(i,i+1);
63+
f2.union(i,i+1);
7264
}
7365

74-
for (int i = 0; i < 10; i++) {
75-
for (int j = 0; j < 10; j++) {
76-
if(forest.findSet(j)==i){
77-
sets.get(i).add(j);
78-
}
79-
}
80-
}
81-
82-
for (int i = 0; i < sets.size(); i++) {
83-
if(sets.get(i).size()!=0){
84-
System.out.print("[");
85-
sets.get(i).stream().forEach(e -> System.out.print(e+ ", "));
86-
System.out.print("]");
87-
}
88-
}
89-
System.out.println();
66+
System.out.println("KOMPRESOWANY SET");
67+
f1.displaySets();
68+
System.out.println("STABILIZOWANA WYSOKOSC SET");
69+
f2.displaySets();
9070
}
9171

9272
}

0 commit comments

Comments
 (0)