Em có một class Generic như này
và một hàm compare
làm sao để em có thể dùng hàm compare này để sử dụng trong class ạ
Em có một class Generic như này
Cậu truyền Compare object vào trong method heapify.
// Sửa lại signature của heapify như thế này:
void heapify(int nodeIndex, IComparer<T>comparison) {
...
if(... && comparison.Compare(..., ...) > 0) {
...
}
}
// Usage
new PriorityQueue<Edge>().heapify(1, new iCompare());
Dạ e cảm ơn ạ