Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shikhart98 authored Jan 8, 2018
1 parent 4d29726 commit c0c72ca
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Compression/src/genericheap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
import java.util.ArrayList;
import java.util.Comparator;

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

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

public genericheap(Comparator<T> ctor) {
public genericheap(Comparator<T> ctor) { // constructor to initialize the generic comparator
this.ctor=ctor;
}

public int size() {
public int size() { // returns the size of the arraylist data
return data.size();
}

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

public void display() {
public void display() { //displays the list
System.out.println(this.data);
}

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

private void swap(int ci, int pi) {
private void swap(int ci, int pi) { // swap function written like this because of the generic property
T ith = data.get(ci);
T jth=data.get(pi);
data.set(ci, jth);
Expand Down

0 comments on commit c0c72ca

Please sign in to comment.