Skip to content

Commit c0c72ca

Browse files
authored
added comments
1 parent 4d29726 commit c0c72ca

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Compression/src/genericheap.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
import java.util.ArrayList;
44
import java.util.Comparator;
55

6-
public class genericheap<T> {
6+
public class genericheap<T> { // create a generic heap class <T> , where T can be of any type.
77

88
private ArrayList<T> data = new ArrayList<>();
99
private Comparator<T> ctor;
1010

11-
public genericheap(Comparator<T> ctor) {
11+
public genericheap(Comparator<T> ctor) { // constructor to initialize the generic comparator
1212
this.ctor=ctor;
1313
}
1414

15-
public int size() {
15+
public int size() { // returns the size of the arraylist data
1616
return data.size();
1717
}
1818

19-
public boolean isEmpty() {
19+
public boolean isEmpty() { // checks whether the list is empty or not :: return true or false for the same
2020
return data.isEmpty();
2121
}
2222

23-
public void display() {
23+
public void display() { //displays the list
2424
System.out.println(this.data);
2525
}
2626

27-
public void add(T integer) {
27+
public void add(T integer) { // in this function we have added the <t> type object into the arraylist and called upheapify
2828
data.add(integer);
2929
upheapify(data.size() - 1);
3030
}
@@ -53,7 +53,7 @@ private boolean isLarger(int i, int j) {
5353
}
5454
}
5555

56-
private void swap(int ci, int pi) {
56+
private void swap(int ci, int pi) { // swap function written like this because of the generic property
5757
T ith = data.get(ci);
5858
T jth=data.get(pi);
5959
data.set(ci, jth);

0 commit comments

Comments
 (0)