I'm trying to implement a generic binary min heap. I have a minHeap class which represents the heap, and a nested Node class which represents nodes. So minHeap consists of Node objects. Node class has two attributes: some generic data and an integer key. The problem is, I cannot for the life of me figure out how to compare two objects of Node type. I've tried implementing Icomparable on Node, overloading operators: I can't get it to work. Here is the basic structure so far (I've removed the unimportant bits):
'''
public class MinHeap<T>
{
static private int INITIAL_CAPACITY = 10;
private Node[] heap = new Node[INITIAL_CAPACITY];
private int heapSize = 0;
private int heapCapacity = INITIAL_CAPACITY;
private class Node
{
private T data;
private int key;
}
...
'''
What I want to do is overload operators such as <, >, == to be able to compare Nodes in the minHeap class' methods. For example, when I insert a new Node into the minHeap, I need to compare the new Node's key to the another Node's key. How could I achieve this?